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