dongzan1970
2014-08-17 19:33
浏览 68
已采纳

SQL查询条件不起作用

I'm working on a search script with pagination but can't get it to work properly.

Here is my query:

$query = "SELECT COUNT(*) FROM server_data WHERE trash = '0' AND server_address LIKE '%$search%' OR title LIKE '%$search%' OR short_desc LIKE '%$search%'";

This is to count how many results there are in the database.

Here is my query for the actual data:

$query = "SELECT * FROM server_data WHERE trash = '0' AND server_address LIKE '%$search%' OR title LIKE '%$search%' OR short_desc LIKE '%$search%' ORDER BY id DESC $limit";

For some reason, this is returning results where trash = 1 and trash = 0, when it should only be returning where trash = 0 obviously. Anybody have any idea why this could be happening?

图片转代码服务由CSDN问答提供 功能建议

我正在使用分页搜索脚本,但无法使其正常工作。

这是我的查询:

  $ query =“SELECT COUNT(*)FROM server_data WHERE trash ='0'AND server_address LIKE'%$ search  %'或标题LIKE'%$ search%'或short_desc LIKE'%$ search%'“; 
   
 
 

这是计算有多少结果 数据库。

这是我对实际数据的查询:

  $ query =“SELECT * FROM server_data WHERE trash ='0'AND server_address  LIKE'%$ search%'或title LIKE'%$ search%'或short_desc LIKE'%$ search%'ORDER BY id DESC $ limit“; 
   
 
 

出于某种原因,这是返回结果,其中trash = 1和trash = 0,当它应该只返回trash = 0时显然。 任何人都知道为什么会发生这种情况?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题