我有以下查询搜索了用户输入数据的剧集指南数据库:
$query = "SELECT *
FROM epguide
WHERE EpisodeTitle LIKE '%$trimmed%'
OR Synopsis LIKE '%$trimmed%'
OR Notes LIKE '%$trimmed%'
ORDER BY o";
这可行,但是当我添加'Series ='$ ser'AND'时它会停止:
$query = "SELECT *
FROM epguide
WHERE Series = '$ser'
AND EpisodeTitle LIKE '%$trimmed%'
OR Synopsis LIKE '%$trimmed%'
OR Notes LIKE '%$trimmed%'
ORDER BY o";
它看起来应该有效。我该怎么做才能解决它?
答案 0 :(得分:3)
使用:
SELECT *
FROM epguide
WHERE Series = '$ser'
AND (EpisodeTitle LIKE '%$trimmed%'
OR Synopsis LIKE '%$trimmed%'
OR Notes LIKE '%$trimmed%')
ORDER BY o
您需要括号来分隔/分组WHERE
子句中的语句。
答案 1 :(得分:2)
你需要决定是否意味着
SELECT * FROM epguide WHERE (Series = '$ser' AND EpisodeTitle LIKE '%$trimmed%') OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%' ORDER BY o
或
SELECT * FROM epguide WHERE Series = '$ser' AND (EpisodeTitle LIKE '%$trimmed%' OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%') ORDER BY o
并适当修改查询。