Error in executing mysql command via PHP

Hi!

I am executing mysql command via PHP is,

$query = mysql_query("select * from table_name");
$query_res = mysql_fetch_array($query);

print_r($query_res);

But I am only getting the first record present in that table, not all the records. Why?

When I am doing the same query on PhpMyAdmin, it works fine and shows me all the records.

mysql_fetch_array() will get the first row of the result set. You will need to run that in a loop until no more rows are present to get all rows.


$rows = array();
while($row = mysql_fetch_array($query)) {
     $rows[] = $row;
}

Thanks a lot. It worked.