PHP MySQL getting top five highest results.?

zandrez

New Member
have a poll table which has 10 categories and I want to view the top 5 results from highest to lowest limit into 5 categories. How can I do this in php and mysql?here are example tablescategories
  • id
  • category_name
Votes
  • id
  • category_id
  • user_id
Users
  • id
  • username
here is my sample query:\[code\]$q = mysql_query("SELECT * from categories");while($data = http://stackoverflow.com/questions/3664233/mysql_fetch_array($q){ $votes = mysql_query("SELECT * from votes where category_id=".$data['id'].""); $data_vote = mysql_nuw_rows($votes); echo $data['category_name']."has".$data_vote."Votes";}\[/code\]I want my output to be like this from the highest votes in a categories\[code\]category1 has 30 votescategory3 has 25 votescategory5 has 23 votescategory2 has 15 votescategory4 has 10 votes\[/code\]
 
Back
Top