我有这个搜索查询,我想基于“folder_restriction”过滤结果,但似乎AND子句不过滤结果。 我哪里做错了?
SELECT *
FROM mod_images
LEFT JOIN mod_folders
ON folder_id = image_folder_id
LEFT JOIN mod_cats
ON cat_id = folder_cat_id
WHERE ((`folder_number` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`titule` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`description` LIKE '%".$search."%') OR ('%".$search."%')) OR
AND `folder_restriction` = '0'
LIMIT 2000
答案 0 :(得分:1)
试试这个: -
SELECT * FROM mod_images
LEFT JOIN mod_folders ON folder_id = image_folder_id
LEFT JOIN mod_cats ON cat_id = folder_cat_id
WHERE
((`folder_number` LIKE '%".$search."%') OR
(`titule` LIKE '%".$search."%') OR
(`description` LIKE '%".$search."%' ))
AND `folder_restriction` = '0'
LIMIT 2000
或尝试删除最后的OR
: -
SELECT *
FROM mod_images
LEFT JOIN mod_folders
ON folder_id = image_folder_id
LEFT JOIN mod_cats
ON cat_id = folder_cat_id
WHERE (((`folder_number` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`titule` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`description` LIKE '%".$search."%') OR ('%".$search."%')))
AND `folder_restriction` = '0'
LIMIT 2000
答案 1 :(得分:0)
SELECT *
FROM mod_images
LEFT JOIN mod_folders
ON folder_id = image_folder_id
LEFT JOIN mod_cats
ON cat_id = folder_cat_id
WHERE (((`folder_number` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`titule` LIKE '%".$search."%') OR ('%".$search."%')) OR
((`description` LIKE '%".$search."%') OR ('%".$search."%')))
AND `folder_restriction` = '0'
LIMIT 2000