Date and now() function

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
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Date and now() function

Post by tommy1987 »

Hi, I want to have a recent posts panel on my site, this will get the most recent posts from 6 tables in a mysql database.
The dates have all been inserted in the same consistent way, with the now() function. Anyone have any suggestions as to how I should do this in SQL? I want to get the most recent one from each table so six in total.

Thanks in advance
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Are you talking about a six table join or six queries from six tables?
tommy1987
Forum Commoner
Posts: 92
Joined: Tue Feb 21, 2006 8:35 pm

Post by tommy1987 »

I will do six queries, one from each table im just looking for what the SQL would look like...
Will it be something like "SELECT title FROM users ORDER BY date LIMIT 1" would that do it?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php $sql = "SELECT title FROM users ORDER BY date DESC LIMIT 0, 1"; ?>
This selects the most recent post in the table (by date).
Post Reply