2010-06-03 49 views
0

有没有办法只显示比某个日期在一个PHP MySQL数组中的项目?我使用这种查询方法和lastpost_cl排序:只显示使用PHP和时间()的MySQL数据库中的某些项目()

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

,我想检查时间将是方式:

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

} 

我怎样才能将二者结合起来,并只显示lastpost_cl那比目前的年龄更老?

回答

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

这假设你使用mysql日期类型之一来存储日期。请参阅手册here

+0

工作很好。谢谢! – Jon 2010-06-03 03:21:08

0

MySQL可以自己做到这一点。只要改变你的查询到这一点:

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

你应该在SQL查询中做到这一点,因为在SQL Server和Web服务器上的时间可能会有所不同。像这样的查询将得到超过一周的一切

SELECT 
* 
FROM properties 
where lastpost_cl < now() - INTERVAL 7 DAY 
ORDER BY lastpost_cl 
相关问题