MySQL过滤器,WHERE

时间:2013-10-31 17:14:46

标签: mysql filter

我的mysql过滤器有问题。如果用户有空字段,则查询不起作用。我该如何解决这个问题,我尝试过发送' NULL'在类型中如果未选择类型,但这也不起作用。

$STH = $DBH->query("
SELECT * 
WHERE store ='$type' and sdn='$status' and price>='$price_s' and price<='$price_e' ORDER BY id DESC LIMIT $setlimit");


$STH = $DBH->query("
SELECT * 
WHERE store ='$type' and sdn='$status' and price>='$price_s' and price<='$price_e' ORDER BY id DESC LIMIT $setlimit");

2 个答案:

答案 0 :(得分:0)

似乎缺少来自,例如如果表是销售,请尝试

$STH = $DBH->query("
SELECT * from sales 
WHERE store='$type' and sdn='$status' and price>='$price_s' and price<='$price_e' 
ORDER BY id DESC LIMIT $setlimit");


$STH = $DBH->query("
SELECT * from sales
WHERE store='$type' and sdn='$status' and price>='$price_s' and price<='$price_e' 
ORDER BY id DESC LIMIT $setlimit");

答案 1 :(得分:0)

您错过了FROM your_table指令

$STH = $DBH->query("
SELECT *  
  

FROM table

WHERE store ='$type' and sdn='$status' and price>='$price_s' and price<='$price_e' ORDER BY id DESC LIMIT $setlimit");

只需输入表格的名称即可(如果字段存在)