douqujin2767 2015-03-27 20:26
浏览 44

每7天更换一次图像,然后在最后一张图像时重复

I am trying to display a piece of content (image for now) that lasts 7 days, then changes to the next piece of content.

There are 6 piece of content I need to cycle through.. after the 7th day on content item #6. I need to start over at content item #1.

The general approach I am taking is, get a UNIX timestamp, and divide by 7 day, and modulus by the total content items.

I saw this as a suggestion but not clear what the $timestamp is referring to?

$weeknumber = $ceil((time() – $starttimestamp) / 604800);

if ($weeknumber > {totalimages}) {
                $ weeknumber = $weeknumber % {totalimages};
}

This (time() - $timestamp) doesn't make sense to me

I'm expecting a return of 1-6 (or 0-5) and then do/load whatever based on that return value. I feel like I'm missing a part of it.

$unixStamp = time();
echo date('r', $unixStamp) . "<br />"; //outputs correct/current date

$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
echo "ARTICLE TO GRAB 1: ".$weekCount1;
echo '<br>';

$weekCount2 = (floor($unixStamp / 604800) % 6);
$weekCount2a = ($unixStamp / 604800) % 6;
$weekCount2b = (floor(time() - $unixStamp / 604800));
echo "ARTICLE TO GRAB 2: ".$weekCount2 .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2: ".$weekCount2b .'<br>';

That being said, I'm also not clear on how I can TEST to ensure it will change/update correctly? (Do I temporarily add some days/weeks to the $unixStamp to force a different date?)

Another attempt and trying to get different values:

$unixStamp = time();
echo date('r', $unixStamp) . "<br /><br />"; //outputs correct/current date
$startDate = strtotime('2015-03-01 00:00:00');


$weekCount1 = (floor($unixStamp / (60000*60*24*7) % 6) + 1);
$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6) + 1;
//$weekCount2a = (floor($startDate - $unixStamp / 604800) % 6);
$weekCount2b = ($unixStamp / 604800) % 6;
$weekCount2c = (floor(time() - $unixStamp / 604800));
$weekCount2d = (ceil($unixStamp / 604800) % 6);
echo "ARTICLE TO GRAB 1: ".$weekCount1 .'<br>';
echo "ARTICLE TO GRAB 2a: ".$weekCount2a .'<br>';
echo "ARTICLE TO GRAB 2b: ".$weekCount2b .'<br>';
echo "ARTICLE TO GRAB 2c: ".$weekCount2c .'<br>';
echo "ARTICLE TO GRAB 2d: ".$weekCount2d .'<br>';

I had added and changed a start date to subtract form the unixStamp, in order to get a time difference form when the rotqation is to start vs the unixStamp and trying to get a return for that. However, it never changes regardless of the start date?

Latest attempt: seems to update when I refresh though, instead of going off the startDate:

  $unixStamp = time();
    $startDate = strtotime('2015-02-1 00:00:00'); 
    $weekCount = ceil($unixStamp - $startDate  / 604800);
    echo "CONTENT ID TO GRAB: ".$weekCount .'<br>';

    if ($weekCount > 6) {
         $weekCount = $weekCount % 6;
         echo "CONTENT TO GRAB: ".$weekCount;
    }
  • 写回答

2条回答 默认 最新

  • duanen19871021 2015-03-27 22:17
    关注

    Updated code: (seems to be working fine now)

      $unixStamp = time();
      $startDate = strtotime('2015-03-27 00:00:00'); 
      $weekCount = ceil(($unixStamp - $startDate)  / 604800) - 1;
      if ($weekCount > 6) {
          $weekCount = $weekCount % 6;
      }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大