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 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? 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. 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
Archived
This topic is now archived and is closed to further replies.