The Little Guy Posted January 16, 2007 Share Posted January 16, 2007 Here is my sql:[b]$sql = mysql_query("SELECT * FROM businesses ORDER by biz_num_votes, biz_vote_10 ASC LIMIT $top_businesses")or die(mysql_error());[/b]biz_num_votes = the total number of people who voted for thisbiz_vote_10 = a number between 0 and 10I would like to have this ordered by biz_vote_10, but if there are 2 business with the same number between 0 and 10, I want the one with more biz_num_votes to be displayed first.The problem is, I don't know how to do this, and I know my code isn't right or the businesses would display correctlyHere is a quick layout of my display:[code]<?phpwhile($row = mysql_fetch_array($sql)){ echo '<a href="#">'.stripslashes($row['biz_name'])";}?>[/code]Here is the full thing:[code]<?phpwhile($row = mysql_fetch_array($sql)){ echo '<a href="#">'.stripslashes($row['biz_name'])."</a> - <strong>".$row['biz_vote_10']."</strong> out of <strong>10</strong><br/ > <strong>".$row['biz_num_votes']."</strong> Votes<br /><br />";}?>[/code] Quote Link to comment Share on other sites More sharing options...
hvle Posted January 16, 2007 Share Posted January 16, 2007 hello nudie,If you want the one with more count displayed first, you would use DESC, not ASC.... order by first_priority, second_priority DESC.....place what to be order first in first priority, and so on.By the way, you have not say what is the problem of the code above. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 16, 2007 Author Share Posted January 16, 2007 OK, that worked but now the lowest number is first, the one between 0 and 10 Quote Link to comment Share on other sites More sharing options...
hvle Posted January 16, 2007 Share Posted January 16, 2007 I don't think I understood you.you want to first, sort the biz_vote_10, then within those biz_vote_10, sort by biz_num_votes?if this is correct, you need to swap the 2 columns:...ORDER by biz_vote_10, biz_num_votes DESC... Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 16, 2007 Author Share Posted January 16, 2007 That is exactly what I want, but that code doesn't work.$sql = mysql_query("SELECT * FROM businesses ORDER by biz_vote_10, biz_num_votes DESC LIMIT $top_businesses")or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
hvle Posted January 16, 2007 Share Posted January 16, 2007 can you post your table structure along with an example table of how you wanted it be like?I'll be back in a few hours. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted January 16, 2007 Author Share Posted January 16, 2007 Never mind, I got It!$sql = mysql_query("SELECT * FROM businesses ORDER by biz_vote_10 DESC, biz_num_votes DESC LIMIT $top_businesses")or die(mysql_error());I needed to order both columns, not just the entire query Quote Link to comment Share on other sites More sharing options...
hvle Posted January 16, 2007 Share Posted January 16, 2007 awesome! Quote Link to comment 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.