0

如何使我的搜索表单仅列出hidden = '0';+ 其余选项的结果?

$stmt = $dbh->prepare("
SELECT *
FROM        users u
LEFT JOIN   menues m
ON          u.user_id = m.restaurant_id
WHERE       (restaurant LIKE CONCAT('%', :term, '%'))
OR          city LIKE CONCAT('%', :term, '%')
");
$stmt->bindParam(":term", $term);
$stmt->execute();   

提前致谢 :)

4

2 回答 2

2

你可以不只是添加

AND hidden = '0'

到您的WHERE子句末尾,以便您的查询结束

.
.
.
WHERE (restaurant LIKE ...
OR city LIKE ...)
AND hidden='0'

顺便说一句hidden真的是基于字符的列吗?如果没有,您应该添加hidden=0(不带单引号)

于 2013-06-02T22:02:16.940 回答
2

好吧,我希望我了解您的需求:

$stmt = $dbh->prepare("
SELECT *
FROM        users u
LEFT JOIN   menues m
ON          u.user_id = m.restaurant_id
WHERE       (((restaurant LIKE CONCAT('%', :term, '%'))
OR          city LIKE CONCAT('%', :term, '%'))
AND         hidden = 0)
");
$stmt->bindParam(":term", $term);
$stmt->execute();   
于 2013-06-02T21:59:17.000 回答