Skip to content Skip to sidebar Skip to footer

Im Only Getting One Set Of Result When Trying To Use Mysql_fetch_array()

function GetVideoInfo( $video_id, $user_id ) { $result = mysql_query('SELECT * FROM `mytable` WHERE video_id = '$

Solution 1:

All of the fetch functions will return a single row, you will need to loop until the result is empty like this (snippet from php.net).

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("ID: %s  Name: %s", $row["id"], $row["name"]);
}

Solution 2:

From the example on the manual page, mysql_fetch_array returns the information on the current pointer of the $result object. This will mean you want to loop through the result until you've fetched everything.

while ($row=mysql_fetch_array($result)) {
    $set[] = $row;
}
print_r($set);

Solution 3:

You need to put the mysql_fetch_array($result) in a loop

while($row = mysql_fetch_array($result))
{
   // do something with $row
}

Post a Comment for "Im Only Getting One Set Of Result When Trying To Use Mysql_fetch_array()"