我有一个与phpmyadmin sql一起正常工作的查询,但不适用于php脚本,它可以工作但什么也没找回
SELECT *
from individuals
where STR_TO_DATE(birthdate, '%d/%m/%Y') >= STR_TO_DATE('01/01/1984', '%d/%m/%Y')
&& STR_TO_DATE(birthdate, '%d/%m/%Y') <= STR_TO_DATE('01/01/2002','%d/%m/%Y')
&& (address LIKE '%جدة%'
|| address LIKE '%جده%'
|| address LIKE '%الطائف%'
|| address LIKE '%مكة%'
|| address LIKE '%مكه%'
|| address LIKE '%رابغ%')
ORDER BY`individuals`.`birthdate` ASC
连接和一切都很好,它可以在没有条件的情况下正常工作
答案 0 :(得分:1)
||
是带引号,而不是OR
!并且也将&&
替换为AND
更改为
SELECT *
from individuals
where STR_TO_DATE(birthdate, '%d/%m/%Y') >= STR_TO_DATE('01/01/1984', '%d/%m/%Y')
AND STR_TO_DATE(birthdate, '%d/%m/%Y') <= STR_TO_DATE('01/01/2002','%d/%m/%Y')
AND (address LIKE '%جدة%'
OR address LIKE '%جده%'
OR address LIKE '%الطائف%'
OR address LIKE '%مكة%'
OR address LIKE '%مكه%'
OR address LIKE '%رابغ%')
ORDER BY`individuals`.`birthdate` ASC
顺便说一句:将生日的数据类型更改为date