Jump to content
  • Advertisement
Sign in to follow this  
jumpjumpjump

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

This topic is 4797 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!