Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/65.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.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如何在单个查询中添加两个where_Php_Mysql - Fatal编程技术网

php如何在单个查询中添加两个where

php如何在单个查询中添加两个where,php,mysql,Php,Mysql,我有以下sql查询,一切正常,但当我放置并发布_date$datetime时,它并没有按照给定的命令检索数据 $datetime="0000-00-00"; $data = mysql_query("SELECT * FROM product_table where category_id=$cat1 or pid=$par or gpid=$gpar and posted_date<>$datetime ORDER BY autoid desc limit $no2,$caco

我有以下sql查询,一切正常,但当我放置并发布_date$datetime时,它并没有按照给定的命令检索数据

$datetime="0000-00-00";

$data = mysql_query("SELECT * FROM product_table where category_id=$cat1 or 
pid=$par or gpid=$gpar and posted_date<>$datetime
ORDER BY autoid desc limit $no2,$cacount")

or die(mysql_error());
请检查行是否正常,可能我在某个地方出错,类别\u id=$cat1或pid=$par或gpid=$gpar和发布的\u日期$datetime

也许我需要两个,一个用于或,另一个用于和


谢谢

尝试将您的情况和使用日期分组

posted_date条件是否与gpid条件一致,还是应始终进行检查?您需要分组,如category_id=$cat1或pid=$par或gpid=$gpar和posted_date$datetime
SELECT * 
FROM product_table 
where (category_id=$cat1 or 
       pid=$par or gpid=$gpar) AND DATE(posted_date) <> DATE($datetime)
ORDER BY autoid desc 
LIMIT $no2, $cacount