PDA

View Full Version : Sorting DB table


Deskdirect
3-17-03, 03:49 PM
I have a database table that needs to be sorted so that it appears newest --- to oldest date wise. I don't know enough about PHP to even know if this is possible.

Would one of you PHP masters give a PHP dummy some assistance? PLEASE!

devinemke
3-17-03, 04:16 PM
assuming the table is called "table" and the field containing the date info is called "date":

$result = mysql_query ('SELECT * FROM table ORDER BY date DESC');

Deskdirect
3-17-03, 05:11 PM
Thanks, perhaps I should explain.............

I am setting up a phpBB and migrated from YaBBSE. The conversion went well; but I noticed that all of the posts are listed in the forum oldest-to-newest - date wise.

I may not be able to do anything about it but I was hoping there was a simple answer. The phpbb_posts table is has a post_time but no date.


$result = mysql_query ('SELECT * FROM phpbb_posts ORDER BY post_time DESC');

The query was followed by - You have an error in your SQL syntax.

Any suggestions?

devinemke
3-17-03, 05:19 PM
i find it hard to believe that there isn't a simple sorting option in the GUI of phpBB. Anyway, what is the field type of "post_time"? Is it just time or is it a full datetime type (YYYY-MM-DD HH:MM:SS)?

Deskdirect
3-17-03, 07:16 PM
Strange but in both phpbb_posts and phpbb_topics both are using - int(11) not Time or DateTime!

This is the time in phpbb_posts 1047151545
This is the time in phpbb_topics 1047151545
This post/topic was made 17 Mar 2003 11:21

???????

devinemke
3-17-03, 07:31 PM
Those are UNIX timestamps (strange that phpBB would not use standard mySQL datetime types). My original query should work fine for timestamps as well. Basically you are sorting by an integer in the reverse order (highest to lowest). You would have to replace whatever SELECT statement phpBB is using to display the records and add "ORDER BY post_time DESC".

Deskdirect
3-17-03, 07:59 PM
Thanks for the help! I will try to sort this out.