如何使用多地点和排序方式


How to Use Multi WHERE and ORDER BY

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

$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";

事实证明它没有用。应该怎么做?

我认为这可能是您要找的

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

试试这个查询...

$sql ="从消息如'%$description%'或标题如'%$description%'按消息排序的主题中选择标题,标题限制为10";