SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a little explanation about mysql_fetch_aray

    Hi
    considering this code:
    Code:
     
    $result = @mysql_query('SELECT * FROM huh ORDER BY pk ASC LIMIT 0, 30');
    while ( $row = mysql_fetch_array($result) ) { 
       echo('<p>' . $row['test'] . $row['pk'] . '</p>'); 
     }
    I need a little explanation on this part:
    Code:
     while ( $row = mysql_fetch_array($result) ) { 
       echo('<p>' . $row['test'] . $row['pk'] . '</p>'); 
     }
    what's the concept?

    thanks a lot for your time

  2. #2
    PHP manual bot bronze trophy Gaheris's Avatar
    Join Date
    Oct 2003
    Location
    Germany
    Posts
    2,195
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_fetch_array will return the next record from the result of your SQL query as an array with numeric and string indices. Other mysql_fetch functions are mysql_fetch_row (only numeric indices), mysql_fetch_assoc (only string indices) and mysql_fetch_object (returns an object).

  3. #3
    ********* Callithumpian silver trophy freakysid's Avatar
    Join Date
    Jun 2000
    Location
    Sydney, Australia
    Posts
    3,798
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    While there are still rows in the mysql result set, the code will fetch each row from the result set as an associative array.

    $row = mysql_fetch_array($result);

    grabs one row from the results set as an associative array where the field names are used for the keys.

    In the echo statement the code is outputing the values of specific fields from the current row in the result set (which are held in the associative array $row).

    The while loop will keep executing until there are no more rows left to fetch in the query result set.

  4. #4
    gimme the uuuuuuuuuuu duuudie's Avatar
    Join Date
    Feb 2004
    Location
    Switzerland
    Posts
    2,253
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you so much guys

    you've been a great help.

    Now I'm a mysql_fetch functions professional

    thumbs up.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •