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
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
Share on other sites

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...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.