查询:隐藏='0'

时间:2013-06-02 21:56:09

标签: mysql

如何让我的搜索表单仅列出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();   

提前致谢:)

2 个答案:

答案 0 :(得分: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();   

答案 1 :(得分:2)

你能不能只添加

AND hidden = '0'

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

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

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