不在不工作的MYSQL

时间:2016-12-08 05:00:53

标签: php mysql search

我正在尝试使用搜索查询在我的网站上设置搜索功能,但我不想让films获得contestId='-1'

以下是我对搜索的查询:

SELECT * FROM film WHERE  MATCH (title, otherInfo, inspiration, description,directedBy,
keywords,producer) AGAINST ('$searchresults' IN NATURAL LANGUAGE MODE )
and contestId not in (select contest_id from contest where contest_id !='-1' ) 
OR title LIKE 'ho%' OR title LIKE '%ho' and isApproved=1 order by film_id desc limit 1

contestId='-1'仍在获得结果。

请帮忙。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

SELECT   *
FROM     film
WHERE    MATCH (title, otherinfo, inspiration, description,directedby, keywords,producer) against ('$searchresults' IN NATURAL language mode )
AND      contestid NOT IN
         (
                SELECT contest_id
                FROM   contest
                WHERE  contest_id ='-1' )
AND     (
                  title LIKE 'ho%'
         OR       title LIKE '%ho' )
AND      isapproved=1
ORDER BY film_id DESC
LIMIT    1

一对错误

  • SELECT contest_id FROM contest WHERE contest_id !='-1'应为SELECT contest_id FROM contest WHERE contest_id ='-1'
  • AND contestId NOT IN (... ) OR title LIKE 'ho%' OR title LIKE '%ho' ....即使有contestId = -1,也会包含记录。 title LIKE 'ho%' OR title LIKE '%ho'应该包含在AND中。像AND (title LIKE 'ho%' OR title LIKE '%ho')