tags:

views:

18

answers:

3

Is there a way to only show the items that are older than a certain date in a php mysql array? I'm using this query method and sorting by lastpost_cl:

$query="SELECT * FROM properties ORDER BY lastpost_cl";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

and I was thinking the way of checking the time would be:

if (time() <= strtotime($lastpost_cl)) {

}

How can I combine the two and only show lastpost_cl that are older that the current time?

+1  A: 
$query="SELECT * FROM properties WHERE lastpost_cl < NOW() ".
    "ORDER BY lastpost_cl";

This assumes you're storing the date using one of mysql date types. See the manual here.

Artefacto
Worked great. Thanks!
Jon
A: 

MySQL can do that on its own. Just change your query to this:

$query="SELECT * FROM properties WHERE lastpost_cl < NOW() ORDER BY lastpost_cl";
VoteyDisciple
A: 

You should do this in the sql query though, because the time on the sql server and web server could be different. A query like this would get everything older than a week

SELECT 
* 
FROM properties
where lastpost_cl < now() - INTERVAL 7 DAY
ORDER BY lastpost_cl
Nathan Reed