• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

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?


0
cbielich
Asked:
cbielich
1 Solution
 
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
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
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 OlsenData Warehouse Architect / DBACommented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now