How to compare all dates in a specific field of a table....?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Malinga
Forum Newbie
Posts: 2
Joined: Sat Jun 23, 2007 5:27 am

How to compare all dates in a specific field of a table....?

Post by Malinga »

So here's the deal...
I'm not an expert at PHP/MySQL, and just build websites for a hobby. Currently I'm building a news display on my front page, from which all details for each news entry will come from a MySQL database with the following fields:

newsid, newsdate, newstitle, newstext
14, 2007-06-23, Under Construction!, As you can see, the site is still under constructi...

that record is just one example to clarify...

Now, on my front page I need the most recent 3 articles to be displayed, whilst all the others can be found on a separate page (news archives)...
What coding can I use to compare all the dates from the table, and find which three articles are the most recent, in order to display only those on the front page?

All help is appreciated,
Thanks
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Code: Select all

SELECT `newstitle`, `newstext` FROM `newstable` ORDER BY `newsdate` DESC LIMIT 0,3;
ORDER BY is what you're after.
Malinga
Forum Newbie
Posts: 2
Joined: Sat Jun 23, 2007 5:27 am

Post by Malinga »

Thanks ever so much super design
Your help is much appreciated
Post Reply