views:

83

answers:

3

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 ?

+7  A: 

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.

Kewley
+1 I was typing a similar answer. This would be my first guess, without seeing the code.
Bill Karwin
@Kewley... will the while loop finish when the fetch has returned all rows? What I mean is... if mysql_num_rows($result) returns 4, will the while loop run 4 times or infinite times?
Hristo
mysql_fetch_accoc will return FALSE when there are no more rows. So the loop will keep going until it has read 4 rows (in this case) and then end. http://php.net/manual/en/function.mysql-fetch-assoc.php
Kewley
+5  A: 

The problem is with your code. You have just told us that PHPMYADMIN returns from mySql fine, so clearly the sql server is not the problem, nor is phpmyadmin.

Your code is wrong, you probably have (inside your super confidential and perfect code) a limit 1 in your staement, or are grabbing the rows incorrectly because you are unaware of how mysql_fetch functions work.

Downvote me because I'm a snarky jerk, but whatever.

A: 

I'm so sorry, i Really forgot about Looping.

Thanks.

egsome
StackOverflow at it's best.
cam8001
Don't worry, loops are clear bad code, they're considering removing it from all programming languages in the next versions. Stay tuned.