Jump to content

SQL ordering


The Little Guy

Recommended Posts

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 this
biz_vote_10 = a number between 0 and 10

I 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 correctly

Here is a quick layout of my display:
[code]
<?php
while($row = mysql_fetch_array($sql)){
echo '<a href="#">'.stripslashes($row['biz_name'])";
}
?>
[/code]

Here is the full thing:
[code]
<?php
while($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]
Link to comment
https://forums.phpfreaks.com/topic/34346-sql-ordering/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/34346-sql-ordering/#findComment-161612
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.