salami1_1 Posted January 3, 2009 Share Posted January 3, 2009 Hi, I'm trying to display all messages from a database with specific ordering but the ordering isn't working as it should be. Mysql version Server version: 5.0.67-community-log Query: SELECT * FROM ".FEEDBACK." WHERE category_link = '$cat' AND (active = '1' OR ip = '$ip') ORDER BY mstatus,votes,id DESC Table layout: CREATE TABLE ics_feedback ( id SMALLINT UNSIGNED NOT NULL auto_increment, category_link SMALLINT NOT NULL, poster_name CHAR(30) NOT NULL, poster_email CHAR(40) NOT NULL, message TEXT NOT NULL, pdate CHAR(22) NOT NULL, ip CHAR(16) NOT NULL, active TINYINT(1) default '0', votes int(4) default '0', sec_id CHAR(25), mstatus TINYINT(1) default '4', PRIMARY KEY (id) ); ALTER TABLE ics_feedback ADD INDEX feedbackindex (active,category_link); Now I want the last added feedback messages displayed first, but the messages where mstatus is high(er) number should be displayed first (this has bigger priority for the id ordering) and then the messages with the most votes should be displayed first (more priority then the order by ID but less then the 'mstatus'). But when the query is executed, its not giving what I expected. At the moment in the db only 1 message has 1 vote the rest 0. And the mstatus is '3' for 3 messages and 0 for the rest. Now I found that the problem seems to be with the 'mstatus' and 'votes'. If their number is higher they are placed at the end instead of at the beginning. Which is weird because of the number would be higher then the rest it should display at the beginning because of the DESC right? Best regards, Quote Link to comment https://forums.phpfreaks.com/topic/139296-solved-order-by-issue/ Share on other sites More sharing options...
Mchl Posted January 3, 2009 Share Posted January 3, 2009 ORDER BY mstatus DESC ,votes DESC ,id DESC Quote Link to comment https://forums.phpfreaks.com/topic/139296-solved-order-by-issue/#findComment-728588 Share on other sites More sharing options...
salami1_1 Posted January 4, 2009 Author Share Posted January 4, 2009 haha no shit thanks! I never knew it was like this I was soo puzzled why it didn't work but this works indeed! thanks problem solved Quote Link to comment https://forums.phpfreaks.com/topic/139296-solved-order-by-issue/#findComment-729246 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.