如何根据startday获取事件,使用Better

时间:2019-07-17 作者:Gregory

我有一个SQL查询,它按Startdate对所有事件进行排序,我将startday定义为$today。

但此查询没有接受从YesStarDay开始,而endday是Tomorrow的事件。

如何在两者之间使用查询?

我的查询

SELECT * FROM wp_posts, `wp_mec_dates` AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=\'publish\' AND wp_icl_translations.language_code=\'$lang\' AND dstart>\'$startday\' and  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6
起始日期为$startday = date("Y-m-d");

编辑:使用文档(&W);救命,我现在在这里:

SELECT * FROM wp_posts, wp_mec_dates AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=\'publish\' AND wp_icl_translations.language_code=\'$lang\' AND ($startday BETWEEN dstart AND dend)AND  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6
但它返回0个结果。任何帮助都将不胜感激!

2 个回复
最合适的回答,由SO网友:Gregory 整理而成

找到解决方案<;3.

在dstart和dend之间的“$startday”处使用

加:或dstart>=\'$开始日期\'

SELECT * FROM wp_posts, wp_mec_dates AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=\'publish\' AND wp_icl_translations.language_code=\'$lang\' AND (\'$startday\' BETWEEN dstart AND dend OR dstart >= \'$startday\') AND  wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6

SO网友:user2243593

Try this

WHERE dstart BETWEEN \'$startdate\' AND \'$enddate\'