我有mysql表,其中包含列section
,is_date_based
(是/否值(,date_start
,date_end
和showhide
查询是
$query = "select * from tabele where section='Festival Wish' and ((is_date_based='No') OR (is_date_based='Yes' and (CURDATE() between date_start and date_end ))) and showhide='0' order by sort_order asc";
条件 1.:现在如果is_date_based='No'
和showhide='0'
,则应显示行...它正在工作...
条件 2. :但是如果id_date_based='Yes'
并且如果current date-time
是between date_start and date_end
和showhide='0'
,那么应该只显示行...
........
但不幸的是,即使 MySQL 表中有必需的值和数据,条件 2也不起作用......
MySQL 表结构为
section is_date_based showhide date_start date_end
Festival Wish Yes 0 2018-09-01 05:00:00 2018-09-05 11:30:00
Festival Wish No 0 0000-00-00 00:00:00 0000-00-00 00:00:00
这里显示了第二条记录,使用上述查询正确显示,但即使当前日期介于 date_start 和 date_end 之间,也不会显示第一条记录......
可能是你需要现在((而不是curdate(。
curdate()
返回日期例如 2018-09-01now()
返回日期 2018-09-05 20:34:00 ..
也可能是你需要时间为您的样品添加 11:30 已经过
去了$query = "select *
from tabele
where section='Festival Wish'
and ( (is_date_based='No')
OR (is_date_based='Yes' and (NOW() between date_start and date_end )))
and showhide='0' order by sort_order asc";