0

我有一个将作者姓名存储在一个表中的系统:

author_id | author_name
        1 | J.K.Rowling
        2 | Ryan Quinn
        3 | Stephen King

和另一个存储书籍并使用上面的 author_id 的表:

book_id | book_name | book_desc | book_author
      1 | Harry Potter | Boy who lived | 1
      2 | End of secrets | Some desc   | 2
      3 | Harry Potter2 | Flying wands | 1

等等..所以我需要进行搜索查询,所以如果我输入单词 Harry,它将显示所有标题中包含“Harry”的书籍或描述或作者姓名有 harry。

这是我第一次在 PHP 中进行搜索。提前致谢

4

1 回答 1

0

如果您的表很大,您可能需要考虑全文搜索。使用标准 SQL,您可以:

select b.book_id, b.book_name, b.book_desc, a.author_name
from books b join
     authors a
     on b.book_author = a.author_id
where b.book_name like '%Harry%' or
      b.book_desc like '%Harry%' or
      a.author_name like '%Harry%;
于 2014-11-02T16:24:44.053 回答