Jump to content

[SOLVED] mysql_fetch_array query - not selecting all records


chrisuk

Recommended Posts

Me again! Another query this time.

 

I have this code, pretty straight forward:

 


<?php

$getusers = "SELECT * from players ORDER BY points DESC ";
$sql= mysql_query($getusers) or die(mysql_error());
$row = mysql_fetch_array($sql, MYSQL_ASSOC);
extract ($row);


//then i use a while loop to make a table:

while ( $row = @mysql_fetch_array ( $sql ) )

?>

 

My issue is, is that it select's all but one of the records. As a workaround I have added a user "blank" and set the values for the fields to 9999, and so far this means that it has not appeared in results and the data that I want has, but I am curious to know why it doesn't select all the records? I'd rather not have to do crude workarounds!

 

Thanks

I had this issue a couple of weeks back. I can't really apply the solution here, but here's a link that helped me: <a href="http://forums.macrumors.com/archive/index.php/t-97209.html">LINK</a>

 

It's because you are doing a query before the while loop.

 

Hope that helps!

Thanks for that guys, that sorted it. I got rid of:

 


<?php

$row = mysql_fetch_array($sql, MYSQL_ASSOC);
extract ($row);

?>

 

and change the while loop:

 


<?php

while ($row = mysql_fetch_array($sql,MYSQL_ASSOC))

?>

 

And that worked immediately.

 

So thanks, and I've learned something!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.