[英]My MySQL query won't work
I have the following query which searched an episode guide database for user inputted data: 我有以下查询,它在情节指南数据库中搜索了用户输入的数据:
$query = "SELECT *
FROM epguide
WHERE EpisodeTitle LIKE '%$trimmed%'
OR Synopsis LIKE '%$trimmed%'
OR Notes LIKE '%$trimmed%'
ORDER BY o";
This works OK, but when I add 'Series = '$ser' AND' it stops: 这可以正常工作,但是当我添加'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";
It looks like it should work. 看起来应该可以使用。 What can I do to fix it?
我该如何解决?
Use: 采用:
SELECT *
FROM epguide
WHERE Series = '$ser'
AND (EpisodeTitle LIKE '%$trimmed%'
OR Synopsis LIKE '%$trimmed%'
OR Notes LIKE '%$trimmed%')
ORDER BY o
You need the brackets to separate/group statements within the WHERE
clause. 您需要使用括号将
WHERE
子句中的语句分隔/分组。
You're going to need to decide whether you mean 您将需要确定您的意思是
SELECT * FROM epguide WHERE (Series = '$ser' AND EpisodeTitle LIKE '%$trimmed%') OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%' ORDER BY o
or 要么
SELECT * FROM epguide WHERE Series = '$ser' AND (EpisodeTitle LIKE '%$trimmed%' OR Synopsis LIKE '%$trimmed%' OR Notes LIKE '%$trimmed%') ORDER BY o
and modify the query appropriately. 并适当地修改查询。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.