Jump to content

Recommended Posts

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,

 

 

Link to comment
https://forums.phpfreaks.com/topic/139296-solved-order-by-issue/
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.