Link to home
Start Free TrialLog in
Avatar of cbielich
cbielichFlag for United States of America

asked on

MySQL not producing the amount of records it says it pulls with php

Here is a weird one I have never seen. My code is:

$sql = "SELECT * FROM table";
$result = mysql_query($sql);
echo $records = mysql_num_rows($result); <- this echos the correct amount of records 98191
$count = 0;
while($row = mysql_fetch_array($result)) {
$count++;
}
echo $count; <- this produces 44 records. Even if I echo $count++ it still 44 records. What in the world would cause this?


Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Interesting.  Try the code below to see if it only produces 44 counts on the screen.
$sql = "SELECT * FROM table";
$result = mysql_query($sql);
echo $records = mysql_num_rows($result); <- this echos the correct amount of records 98191
$count = 0;
while($row = mysql_fetch_array($result)) {
echo $count++."-";
}
echo $count;

Open in new window

Have you tried echoing something from the fetched row in addition to just incrementing your counter?

Do you get more than 44 rows worth of data printed?
Avatar of cbielich

ASKER

@Dave - I did that already still 44

@jay - yes I did a print_r($row); and produced 44 records

yeah Im scratching my head on this one
Avatar of Vel Eous
Vel Eous

What is the content of a var_dump($result) and an echo of mysql_num_rows($result) before and after your while loop?

Could $result be getting overwritten anywhere?
ASKER CERTIFIED SOLUTION
Avatar of Kent Olsen
Kent Olsen
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Ok that seems to produce better results

91899 0-1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18 ... 91893-91894-91895-91896-91897-91898-91899

... = yada yada yada :)
Interesting difference.
So what is happening?