Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    What am I trying to do, is to create a library of functions, which aim to make it easier for people to interact with mysql via PHP.

    I have developed functions for SELECT, INSERT UPDATE and DELETE and I am just testing/debugging.

    I have run into a problem.

    I have a function to extract all rows from a particular table (the table is the only argument).

    I used mysql_fetch_row but that only returns one row?

    Here is the function I used,
    PHP Code:
    function getAllRows $table )
        {
            
    // connect to database
            
    include("db/config.php");

            
    $table trim($table);
            if(empty(
    $table))
                {
                    return 
    null;
                }
            
    $select_q "SELECT * FROM $table";
            
    $select_res mysql_query($select_q) or die("Error in getAllRows, '$table' " mysql_error());
            
    $rows_returned mysql_num_rows($select_res);
            if(
    $rows_returned 0)
                {
                    return 
    mysql_fetch_row($select_res);
                }
        } 
    And to call that I use something like:
    PHP Code:
    $array getAllRows"bifflib");

            while(
    $row mysql_fetch_array($array))
                {
                    echo 
    "Fullname: $row[fullname]";
                    echo 
    "$row[address]";
                    echo 
    "\n"
                } 
    Any pointers? Thanks a bunch

  2.  

  3. #2
    Junior Member cdwhalley.com's Avatar
    Join Date
    Apr 2006
    Location
    UK
    Posts
    1
    Member #
    13096
    I'm not sure if this is what you wanted, but, in the simplest form, the way to output all the rows from a table is like this:
    PHP Code:
    $result=mysql_query("SELECT * FROM table");
    while (
    $row mysql_fetch_array) {//loop through each row
          
    extract($row);//split the fields of the row into individual variables named after the field - in this example say the fields are title and description
          
    echo "<b>".$title."</b><br/>".$description."<br/>";//output the 2 variables with some formatting

    This would output the title and description of each row going down the page until its gone through all the results.

    Like I said, I'm not sure of what you're asking for-so I'm sorry if this doesn't answer your question...

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Thanks for the reply, but I solved it by just returning the result id.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:18 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com