fez Posted April 30, 2011 Share Posted April 30, 2011 Hello, I'm new! I am trying to populate a list of locations based on ratings. I can populate the list just fine but it's displaying every record in the table. Is there a way of only looping 4 times so as to just display the top 4 records? Here's the code: $result = mysql_query("SELECT * FROM locations ORDER BY rating DESC"); while($row = mysql_fetch_array($result)) { echo $row['name']; echo "<br>; } Thankyou in advance for any help Quote Link to comment https://forums.phpfreaks.com/topic/235188-looping-through-a-database-table-a-limited-number-of-times/ Share on other sites More sharing options...
JKG Posted April 30, 2011 Share Posted April 30, 2011 SELECT * FROM locations ORDER BY rating DESC LIMIT 0, 4 Quote Link to comment https://forums.phpfreaks.com/topic/235188-looping-through-a-database-table-a-limited-number-of-times/#findComment-1208642 Share on other sites More sharing options...
fez Posted April 30, 2011 Author Share Posted April 30, 2011 Excellent, thank you Quote Link to comment https://forums.phpfreaks.com/topic/235188-looping-through-a-database-table-a-limited-number-of-times/#findComment-1208649 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.