dongyoucha0645 2015-08-03 07:50
浏览 38

PHP日历期(每周)

I doing calendar and I'm now stacked on week period of event. I can't do that, it works, but only for next month and others months not.

$i = 1; 

            $den = $post->day;
            $mesic = $array['month'];
            $rok = $array['year'];
            $minusDays = $this->numDays(date('l', $den.".".$mesi.".".$rok));
            $startedWeek = date('W', strtotime($den.".".$post->month.".".$post->year));
            $actualWeek  = date('W', Time());

            $startedWeek = $actualWeek - $startedWeek;


            for($i; $i<6; $i++){
                if($i==1){
                $startedWeek = $startedWeek;
            }else{
                $startedWeek = $startedWeek+1;
            }
                $plusDay = date('j', strtotime($den.".".$mesic.".".$rok." + ".$startedWeek." weeks - ".$minusDays." days"));
                $plusWeek = date('n',strtotime($den.".".$mesic.".".$rok." + ".$startedWeek." weeks - ".$minusDays." days"));
                $plusYear = date('Y',strtotime($den.".".$mesic.".".$rok." + ".$startedWeek." weeks - ".$minusDays." days"));

                       echo "<input type='hidden' class='interval' data-id='".$post->id."' data-name='".$post->name."' data-d='".$plusDay."' data-day='".$plusDay."' 
                       data-before='".$post->remindBefore."' data-unit='".$post->remindBeforeUnit."' data-remindBy='".$post->remindBy."' data-remindInterval='".$post->remindInterval."' 
                       data-eventTimeH='".$post->remindH."' data-eventTimeM='".$post->remindM."'>";             
                                }

$post->day is day of period, $array['month'] is now listed month, $array['year'] is now listed year. Function numDays returning 0-6 deppends on what day is it. Thank you. It must be in hidden becouse HTML 5 calendar.

There is it ok, it is in column St, next month is same, but 2 months next it is in column Čt.

enter image description here

enter image description here

  • 写回答

1条回答 默认 最新

  • dougu3988 2015-08-03 08:56
    关注

    Ok i did solution, first is to get startDate of period

    $dayOfWeek = date('w', strtotime($post->day.".".$post->month.".".$post->year)); // day of week to start period 
    

    after this i set variable of first day, which is 1. It will go to cyclus so it is 0. After added this variable i loop in cycle every day and check if actual day is Wednesday or Tuesday etc....

    $dd=0;
    
                            for($i=1; $i<7; $i++){
    
                                for($c=0; $c<7; $c++){
                                    $dd++;
                                    $actualDayOfWeek = date('w', strtotime($dd.".".$array['month'].".".$array['year']));
                                    $plusDay = date('j', strtotime($dd.".".$array['month'].".".$array['year']));
                                    if($dayOfWeek != $actualDayOfWeek){
                                    }else{
    
                                        $actualDayOfWeek = date('w', strtotime($dd.".".$array['month'].".".$array['year']));
                                        $plusDay = date('j', strtotime($dd.".".$array['month'].".".$array['year']));
                                        echo "<input type='hidden' class='interval' data-id='".$post->id."' data-name='".$post->name."' data-d='".$dd."' data-day='".$plusDay."' 
                                      data-before='".$post->remindBefore."' data-unit='".$post->remindBeforeUnit."' data-remindBy='".$post->remindBy."' data-remindInterval='".$post->remindInterval."' 
                                      data-eventTimeH='".$post->remindH."' data-eventTimeM='".$post->remindM."'>";  
                                        break;
                                    }
                                }
    
    
                            }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)