1

I have a problem with my mysql filter. If user has an empty field, the query doesn't work. How can I fix this, I have tried sending 'NULL' at type if type not selected, but this doesn't work too.

$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");
4

2 回答 2

0

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

$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");
于 2013-10-31T17:26:02.960 回答
0

你错过了FROM your_table指令

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

从表

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

只需输入表的名称,它应该可以工作(如果存在字段)

于 2013-10-31T17:27:21.877 回答