简体   繁体   中英

PHP calendar periods (weekly)

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.

在此处输入图片说明

在此处输入图片说明

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;
                                }
                            }


                        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM