如何使用Multi WHERE和ORDER BY

时间:2016-02-10 16:25:02

标签: php database

我正在我的博客上组装一个搜索框。默认情况下,脚本如下:

$sql = "SELECT id, title FROM topics WHERE message LIKE '%" . $description . "%' ORDER BY message LIMIT 10";

此脚本仅搜索邮件行中的数据。我想添加另一行。例如title

我在希望关键字中修改了这样的脚本将跟踪消息行和标题:

$sql = "SELECT id, title FROM topics WHERE message, title LIKE '%" . $description . "%' ORDER BY message, title LIMIT 10";

原来它不起作用。应该怎么做?

2 个答案:

答案 0 :(得分:1)

我认为这可能是你正在寻找的东西

"SELECT id, title FROM topics WHERE message LIKE '%" . $description . "%' or title LIKE '%" . $description . "%' ORDER BY message, title LIMIT 10";

答案 1 :(得分:1)

尝试此查询...

$sql = "SELECT id, title FROM topics WHERE message LIKE '%$description%' OR title LIKE '%$description%' ORDER BY message, title LIMIT 10";