Tuesday, 28 August 2018

MySQL returns only the first line of the query result!

I've used my server for testing PHP & MySQL Applications long time ago.

Suddenly, When i try to execute any query on the any table in any database, i get only the first row in the result of the query !
I checked the configuration file, and didn't see anything strange there.
OS: Linux / Ubuntu 10.04 64bit Server Edition, Web Server: Apache/2.2.14, MySQL Client: 5.1.41, MySQL Server: 5.1.41-3ubuntu12.3 (Ubuntu)
And, I'm sure that there's no error in my PHP Code, While when i use phpMyAdmin, i get all rows normally !.
Where should be the problem ?

It would help if you posted your code, but I'm guessing that your code doesn't have a loop that fetches each row.
<?php

$Result = mysql_query( $Query );

while( $Row = mysql_fetch_assoc( $Result ) ) //keep going while there are more rows
{
    print_r( $Row );
}

mysql_fetch_accoc and mysql_fetch_array functions only return one row at a time (consecutively) so you need to run them for each row.

0 comments:

Post a Comment