Jump to content

How To Sort Data Table By 3 or More Variable?


phpBeginner06

Recommended Posts

How can I sort 3 or more variables in a datatable; that displays in a web page. So far I can only sort two; here is what I have got so far.

[code]$result = mysql_query("select * from messeges order by Date, Time desc");[/code]

This is what I want to do (but it did not work like this).

[quote]$result = mysql_query("select * from messeges order by Date, Time, SpecificTime desc");[/quote]

Anyone know how to do this?
If I do it like this:

[code]$result = mysql_query("select * from messeges order by Date, Time desc, SpecificTime desc");[/code]

Will the datatable sort in this fashion:

[quote]First Sorted By: Date and Then Sorted By: Time, and Finally Sorted By: SpecificTime[/quote]

Will it be displayed/sorted like this?
well i dont quite understand your last question, but the "desc" at the end of the query means that if you have a table that looks like this:

ID    User_Name
1.      User1
2.      User2
3.      User3

then you query it by going "SORT BY ID, User_Name desc" ( this meaning sort bi ID first and if record id is == to another record, then sort by User_Name in that record...), youll get these results:

ID    User_Name
3.      User3
2.      User2
1.      User1


im 99% sure of this, but id like someon to back me up

anywayz, try in on your code and see if it works, if not, then let us know, and well come up with another possible solution

Good Luck

I hope that helps

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.