安排发布 - 仅在某些时间或将来的任何时间或重复显示某些内容 [英] Schedule Post - Displaying Some Content only for Some time or any time in future or Repitative

查看:34
本文介绍了安排发布 - 仅在某些时间或将来的任何时间或重复显示某些内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仅在一段时间或几天内显示某些内容我在数据库中有开始时间,开始日期,结束时间和结束日期,以便当这次从数据库中获取数据时,应该检查日期并相应地显示内容

I am trying to display some content only for some time or some days I have start time, start date, end time and end date in database so that when the data is fetched from database this time and dates should be checked and display the content accordingly

我尝试过的代码

$startDateTime = strtotime($result['StartDate']." ".$result['StartTime']);
$endDateTime = strtotime($result['EndDate']." ".$result['EndTime']);
$now = time();

echo "START : ".$startDateTime;
echo "<br/>END : ".$endDateTime;
echo "<br/>CURRENT : ".$now;
if($now >= $startDateTime && $now <= $endDateTime){
echo $result['content'];

}

但它每次都显示内容不起作用

But its not working its displaying the content every time

请帮帮我

提前致谢

推荐答案

与其使用 time() 函数,不如尝试将 '$now' 创建为 strtotime("now").

Rather than using the time() function - try creating '$now' as strtotime("now").

此外,作为调试步骤,它可能会帮助您回显比较,看看它们是否以您期望的方式评估.

Also, as a debugging step, it probably would have helped you to echo the comparisons to see if they evaluated the way that you expected.

实际上 - 我只是完全按照原样尝试了您的代码...除了我对开始和结束日期和时间进行了硬编码.它奏效了,所以改用 strtotime("now") 可能不会有什么不同.

Actually - I just tried your code exactly as it was...Except that I had hard coded values for the starting and ending dates and times. And it worked, so switching to use strtotime("now") will probably not make a difference.

打印出来的值是什么?你没有告诉我们.

What are the values that were printed out? You didn't tell us.

所以 VoronoiPotato 可能是对的...您为 StartDate/StartTime 和 EndDate/EndTime 存储的值一定有问题.

So VoronoiPotato is probably right...The values you are storing for StartDate/StartTime and EndDate/EndTime must have something wrong with them.

如果您像这样更改程序(以添加更多调试),程序的输出是什么:

What is the output of your program if you change it like this (to add more debugging):

$startDateTime = $result['StartDate'] . " " . $result['StartTime'];
$endDateTime = $result['EndDate'] . " " . $result['EndTime'];
$now = time();

echo "START : " . $startDateTime."<br />\n";
echo "END : " . $endDateTime . "<br />\n";

$startDateTime = strtotime($startDateTime);
$endDateTime = strtotime($endDateTime);

echo "Start as time: " . $startDateTime . "<br />\n";
echo "End as time: " . $endDateTime . "<br />\n";

echo "CURRENT : " . $now . "\n";

if (($now >= $startDateTime) && ($now <= $endDateTime)) {
    echo $result['content'];
}

这篇关于安排发布 - 仅在某些时间或将来的任何时间或重复显示某些内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆