Peanuts
Peanuts

Reputation: 53

Order from multiple columns

So here is my code basically what it selects is a support ticket I am trying to make it so that it selects all the tickets from the user however when someone replies to the ticket I need that one to be at the top just wondering why the two orders that I have on this select don't work how intended. Thankyou.

$result = mysql_query("SELECT * FROM `usr_tickets` 
                         WHERE `username` = '$username' 
                         ORDER BY `id` DESC, `replied` DESC")or die(mysql_error()); 

So the problem is more here on the line

ORDER BY `id` DESC, `replied` DESC")or die(mysql_error());

Upvotes: 0

Views: 44

Answers (1)

AbraCadaver
AbraCadaver

Reputation: 78994

The id will be created in order when the ticket is created (and they will be unique) and you sort on that first. You need to sort on replied first which I assume is a date or time:

ORDER BY `replied` DESC, `id` DESC

Upvotes: 1

Related Questions