News script, but posts are "out of order"?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
scr0p
Forum Newbie
Posts: 23
Joined: Mon May 05, 2003 6:49 pm
Location: NY

News script, but posts are "out of order"?

Post by scr0p »

When someone posts, It seems like the post gets put at a random location within the database, I have these files: Nick, Email, Topic, Body, and ID (auto increment).

I want the newest post to be on top on my php page, how can I do this?

Right now I am added 3 fields, IP, Date, and Icon, (will hold a URL to a little icon for each user that posts). I want the user to be able to sort by date or by nick..etc but ill save that question for later on after I get the newest post on top :D
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You just need to add an ORDER BY statement to the end of the SELECT query:
http://www.mysql.com/doc/en/SELECT.html

Code: Select all

SELECT field1, field2, field3 FROM table ORDER BY field1
Mac
Post Reply