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?


LVL 1
cbielichAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
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

0
jaydmCommented:
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?
0
cbielichAuthor Commented:
@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
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Vel EousResearch & Development ManagerCommented:
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?
0
Kent OlsenDBACommented:
Try the code below.  

I believe that the echo statement should echo the line, not actually do the assignment.


Kent

$sql = "SELECT * FROM table";
$result = mysql_query($sql);
$records = mysql_num_rows($result); <- this echos the correct amount of records 98191
echo $records
$count = 0;
while($row = mysql_fetch_array($result)) {
echo $count++."-";
}
echo $count;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cbielichAuthor Commented:
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 :)
0
Dave BaldwinFixer of ProblemsCommented:
Interesting difference.
0
cbielichAuthor Commented:
So what is happening?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.