Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用php和time()仅显示mysql数据库中的某些项_Php_Mysql_Sql - Fatal编程技术网

使用php和time()仅显示mysql数据库中的某些项

使用php和time()仅显示mysql数据库中的某些项,php,mysql,sql,Php,Mysql,Sql,有没有办法在php mysql数组中只显示比某个日期早的项目?我使用此查询方法并按lastpost\u cl排序: $query="SELECT * FROM properties ORDER BY lastpost_cl"; $result=mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); 我在想检查时间的方法是: if (time() <= strtotime($lastpost_cl)) {

有没有办法在php mysql数组中只显示比某个日期早的项目?我使用此查询方法并按lastpost\u cl排序:

$query="SELECT * FROM properties ORDER BY lastpost_cl";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();
我在想检查时间的方法是:

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

}
if(time()
$query=“SELECT*FROM properties WHERE lastpost_cl

这假设您正在使用mysql日期类型之一存储日期。请参阅手册。

mysql可以自行完成此操作。只需将查询更改为:

$query="SELECT * FROM properties WHERE lastpost_cl < NOW() ORDER BY lastpost_cl";
$query=“从属性中选择*,其中lastpost\u cl
但是,您应该在sql查询中这样做,因为sql server和web server上的时间可能不同。像这样的查询会使所有内容都超过一周

SELECT 
* 
FROM properties
where lastpost_cl < now() - INTERVAL 7 DAY
ORDER BY lastpost_cl
选择
* 
从属性
其中lastpost_cl
SELECT 
* 
FROM properties
where lastpost_cl < now() - INTERVAL 7 DAY
ORDER BY lastpost_cl