Sign in to follow this  

[web] Double order by in mysql, int and timestamp

This topic is 4546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am back to working on my forum system, and I would like to order the topics from global annoucements down to regular posts, plus order by the timestamp. Here is the query I am currently using, to no avail. :(
			$sql = "SELECT t.*, u.username, u.user_id 
				FROM ".TOPICS_TABLE." t, ".USER_TABLE." u ".
				"WHERE t.fid = '".$fid."'
				AND t.topic_author = u.user_id
				ORDER BY t.topic_time DESC, t.topic_type DESC
				LIMIT ".$start.", ".$config['topics_per_page'];


Share this post


Link to post
Share on other sites
By the looks of it, the columns listed in your ORDER BY clause are the wrong way around. Remember that when using ORDER BY, it will order the columns in the order you have written them. So in the SQL you have posted, it will order by the timestamp first and then the topic type after.

Try this:


$sql = "SELECT t.*, u.username, u.user_id
FROM ".TOPICS_TABLE." t, ".USER_TABLE." u ".
"WHERE t.fid = '".$fid."'
AND t.topic_author = u.user_id
ORDER BY t.topic_type DESC, t.topic_time DESC
LIMIT ".$start.", ".$config['topics_per_page'];




Also, to help you out a bit in the future (assuming I'm right about the ordering):

Quote:
Original post by jumpjumpjump
...and I would like to order the topics from global annoucements down to regular posts, plus order by the timestamp.


Notice the order in which you've listed the column names when explaining the problem with us. This is the same order you need to list them in your query.

Share this post


Link to post
Share on other sites

This topic is 4546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this