douqian5553
douqian5553
2014-02-05 08:23
浏览 132
已采纳

循环编辑时$ i = 0

I think this is fairly simple, just not a php coder. Researching and reading posts I narrowed down my issue to this piece of code, but not sure how to edit. Things found and tried throw error.

The following code works fine and gives me the results for the current date (today) and previous 6 days. I want to try and change so rather than obtaining the past I want to show the future events. So today and next 6 days.

$i=0;
while ($i<=6){
    $labeldate=date('m/d',mktime(0,0,0,$sm,$sd-$i,$sy));
    $_SESSION['statistic_week'] = date('Y-m-d',mktime(0,0,0,$sm,$sd-$i,$sy));

    $statistic = querySQL('statistic_week_def');
    foreach ($statistic as $row) {
        $statistic_week_def[$i] = ($row->paxsum) ? $row->paxsum : 0; 
    }
    $labels[] = $labeldate;

$i++;
}

图片转代码服务由CSDN问答提供 功能建议

我认为这很简单,只是不是php编码器。 研究和阅读帖子我把我的问题缩小到这段代码,但不知道如何编辑。 找到并尝试的东西抛出错误。

以下代码工作正常,并为我提供当前日期(今天)和前6天的结果。 我想尝试改变,而不是获得过去,我想展示未来的事件。 所以今天和未来6天。

  $ i = 0; 
while($ i&lt; = 6){
 $ labeldate = date('m / d',mktime  (0,0,0,$ sm,$ sd- $ i,$ sy)); 
 $ _SESSION ['statistic_week'] =日期('Ym-d',mktime(0,0,0,$ sm,  $ sd- $ i,$ sy)); 
 
 $ statistic = querySQL('statistic_week_def'); 
 foreach($ statistic as $ row){
 $ statistic_week_def [$ i] =($ row-&gt  ; paxsum)?  $ row-&gt; paxsum:0;  
} 
 $ labels [] = $ labeldate; 
 
 $ i ++; 
} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dqyy38265
    dqyy38265 2014-02-05 08:27
    已采纳

    Use +$i in the date functions instead of -$i, this will add days rather then subtract them.

    $i=0;
    while ($i<=6){
        $labeldate=date('m/d',mktime(0,0,0,$sm,$sd+$i,$sy));
        $_SESSION['statistic_week'] = date('Y-m-d',mktime(0,0,0,$sm,$sd+$i,$sy));
    
        $statistic = querySQL('statistic_week_def');
        foreach ($statistic as $row) {
            $statistic_week_def[$i] = ($row->paxsum) ? $row->paxsum : 0; 
        }
        $labels[] = $labeldate;
    
    $i++;
    }
    
    点赞 评论
  • douduan6731
    douduan6731 2014-02-05 08:29
    <?php
        $i = 0;
        while ($i <= 6) {
            $time = mktime(0, 0, 0, $sm, $sd + $i, $sy)
            $labeldate = date('m/d', $time);
            $_SESSION['statistic_week'] = date('Y-m-d', $time);
            $statistic = querySQL('statistic_week_def');
            foreach ($statistic as $row) {
                $statistic_week_def[$i] = ($row->paxsum) ? $row->paxsum : 0; 
            }
            $labels[] = $labeldate;
            $i++;
        }
    ?>
    
    点赞 评论

相关推荐