tHud Posted November 4, 2010 Share Posted November 4, 2010 Currently I have 5 entries in my table. Entring this query displays all five in the correct order. SELECT * FROM products ORDER BY count DESC LIMIT 16 However, using this code, the first result is omitted and the last four are displayed. $query="SELECT * FROM products ORDER BY count DESC LIMIT 16"; $result = mysql_query($query); $row = mysql_fetch_array($result); echo '<div>'; while ($row = mysql_fetch_array($result)) { echo '<div>'.$row[product].'</div> <div>'.$row[count].'</div>'; } echo '</div>'; Can someone help me find my error? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/217743-incorrect-results-from-mysql_fetch_array-loop/ Share on other sites More sharing options...
AbraCadaver Posted November 4, 2010 Share Posted November 4, 2010 Delete this: $row = mysql_fetch_array($result); You're fetching the first row and then throwing it away before the loop, why? Quote Link to comment https://forums.phpfreaks.com/topic/217743-incorrect-results-from-mysql_fetch_array-loop/#findComment-1130251 Share on other sites More sharing options...
tHud Posted November 4, 2010 Author Share Posted November 4, 2010 I don't know why. I guess it's code I routinely paste. However, I knew that I had read something about that in these forums but I was unable to find it due to the search function being unavailable. It clearly shows a fundamental misunderstanding on my part. I won't make that mistake again! Thank you AbraCadaver. Quote Link to comment https://forums.phpfreaks.com/topic/217743-incorrect-results-from-mysql_fetch_array-loop/#findComment-1130254 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.