0

I have been trying to debug this for quite a while now with no success.

It seems that my mySQL query breaks as soon as I add a where clause to the below query.

Note this returns no results when it should:

SELECT * FROM `workorders` WHERE (`status`='Open') AND 
 `job_site_name` LIKE '%".$searchword."%'  ORDER BY `date_promised` ASC LIMIT 20

This is the same query without the where clause and it returns results as expected, but I need the where status=Open as part of the query...

SELECT * FROM `workorders` WHERE 
 `job_site_name` LIKE '%".$searchword."%'  ORDER BY `date_promised` ASC LIMIT 20

Furthermore, this works (and shows that the status column exists and works in other cases):

SELECT * FROM `workorders` WHERE (`status`='Open') AND `invoice_number` LIKE 
  '%".$searchword."%'  ORDER BY `date_promised` ASC LIMIT 20

I appreciate any assistance in identifying the cause of this problem.

Many thanks in advance!

4

1 回答 1

0

问题似乎是两个标准都没有满足。如果您需要使用OR子句,那么您可以这样做

SELECT * 
FROM `workorders` 
WHERE (`status`='Open' 
   OR `job_site_name` LIKE '%".$searchword."%')
ORDER BY `date_promised` ASC 
LIMIT 20
于 2013-03-05T22:56:37.517 回答