Prank Posted August 30, 2006 Share Posted August 30, 2006 Hi Guys,I have a table with 5 records in it, when I select the records (even just using SELECT * FROM cars) it will sometimes retrieve 3 records and sometimes 4, never the whole amount. I have never seen this happen before. If I run the query in phpmyadmin it returns all records. I dont understand how this could happen, the Statement could not be more simple.Anyone know why this could be happening?Christian Quote Link to comment Share on other sites More sharing options...
.josh Posted August 30, 2006 Share Posted August 30, 2006 please post the code that you are using to retrieve and display the information. Quote Link to comment Share on other sites More sharing options...
Prank Posted August 30, 2006 Author Share Posted August 30, 2006 Its happening in several places, each with re-written code.The code couldnt be more simple.Heres one example;[code] $q = "SELECT * FROM cars"; $qr = mysql_query($q) or die(mysql_error()); $r = mysql_fetch_assoc($qr); echo '<strong>Select a link category</strong><br />'; while($r = mysql_fetch_assoc($qr)){ echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />'; } // while[/code]Thanks. Quote Link to comment Share on other sites More sharing options...
Satria Ox41464b Posted August 30, 2006 Share Posted August 30, 2006 [code]<?php $q = "SELECT * FROM cars"; $qr = mysql_query($q) or die(mysql_error()); $r = mysql_fetch_assoc($qr); // <- You already get one row here echo '<strong>Select a link category</strong><br />'; while($r = mysql_fetch_assoc($qr)){ // and ofcourse overhere total loops will be minus one of total rows echo '<a href="links.php?do=listlinks&cat='.$r['name'].'">'.$r['name'].'</a><br />'; } // while?>[/code] Quote Link to comment Share on other sites More sharing options...
.josh Posted August 30, 2006 Share Posted August 30, 2006 howcome you do a mysql_fetch_assoc, and then do a loop with it again? when you do it the first time, it increments the internal pointer, so that when you start your loop, it starts on the next position, so you're missing out on echoing the first row. Quote Link to comment Share on other sites More sharing options...
Prank Posted August 30, 2006 Author Share Posted August 30, 2006 Ahh crap, I didnt even pick up on that.Thanks heaps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.