0

我正在尝试对完整日历实施重复事件选项。我只在 db 中存储事件的一个实例及其重复详细信息。

根据重复的细节,我试图从 php 代码中重复事件,我在下面发布。

       $calendar_query = "select * from test.calendar where User_Id = 07";
    $Calendar_res = mysql_query($calendar_query) or die(mysql_error());


    while ($calendar_row = mysql_fetch_assoc($Calendar_res)) {
    $flag=false;
    $cal_id=$calendar_row['Calendar_Id'];
    $Repeating_query="select * from repeating_event where Calendar_id='$cal_id'";
    $Repeating_res = mysql_query($Repeating_query) or die(mysql_error());

    while ($repeating_row = mysql_fetch_assoc($Repeating_res)) {

    if($repeating_row['repeats']==0){
    $flag=true; $i=0;
    while($i<$repeating_row['ends_after']){
    if($i==0){

    $eventsArray['id'] =  $calendar_row['Calendar_Id'];
    $eventsArray['userid'] = $calendar_row['User_Id'];
    $eventsArray['title'] = $calendar_row['Event_Title'];
    $eventsArray['start'] = date('Y-m-d H:i:s', strtotime($calendar_row['StartDateTime']));
    $eventsArray['end'] = date('Y-m-d H:i:s', strtotime($calendar_row['EndDateTime']));
    $eventsArray['description'] = $calendar_row['Event_Desc'];
    $eventsArray['venue']=$calendar_row['Event_Venue'];
    $d1=strtotime($calendar_row['StartDateTime']);
    $d2=strtotime($calendar_row['EndDateTime']);
    if($d1==$d2){
    $eventsArray['allDay'] = true;
    }
    else{
    $eventsArray['allDay'] = false;
    }
    }   

    else{

    $eventsArray['id'] =  $calendar_row['Calendar_Id'];
    $eventsArray['userid'] = $calendar_row['User_Id'];
    $eventsArray['title'] = $calendar_row['Event_Title'];
    $eventsArray['start'] = date('Y-m-d H:i:s', strtotime($calendar_row['StartDateTime']) + ($repeating_row['repeats_every']*86400));
    $eventsArray['end'] = date('Y-m-d H:i:s', strtotime($calendar_row['EndDateTime']) + ($repeating_row['repeats_every']*86400));
    $eventsArray['description'] = $calendar_row['Event_Desc'];
    $eventsArray['venue']=$calendar_row['Event_Venue'];
    $d1=strtotime($calendar_row['StartDateTime']);
    $d2=strtotime($calendar_row['EndDateTime']);
    if($d1==$d2){
    $eventsArray['allDay'] = true;
    }
    else{
    $eventsArray['allDay'] = false;
    }
    }  
    $i++;
    }
    }
    }

$events[] = $eventsArray;

}

echo json_encode($events);

输出是:

[{"id":"20","userid":"7","title":"Suresh Birthday","start":1357686000,"end":1357686000,"description":"suresh birthday on 9t april","venue":"Bangalore","allDay":true},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-12-01 01:00:00","end":"2012-12-01 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"23","userid":"7","title":"asdfasd","start":1363042800,"end":1363042800,"description":null,"venue":null,"allDay":true},
{"id":"70","userid":"7","title":"asdf","start":1358204400,"end":1358204400,"description":"asdf","venue":"asdf","allDay":true},
{"id":"71","userid":"7","title":"rahj","start":1358895600,"end":1358895600,"description":"","venue":"as","allDay":true},
{"id":"81","userid":"7","title":"cc","start":1356908400,"end":1356908400,"description":"cc","venue":"","allDay":true},
{"id":"82","userid":"7","title":"kk","start":1358722800,"end":1358722800,"description":"","venue":"","allDay":true},
{"id":"83","userid":"7","title":"mm","start":1359327600,"end":1359327600,"description":"","venue":"","allDay":true},
{"id":"84","userid":"7","title":"vv","start":1359068400,"end":1359068400,"description":"","venue":"","allDay":true},
{"id":"85","userid":"7","title":"zz","start":1358463600,"end":1358463600,"description":"zz","venue":"zz","allDay":true},
{"id":"87","userid":"7","title":"qq","start":1358118000,"end":1358118000,"description":"qq","venue":"qq","allDay":true}]

预期结果:-

[{"id":"20","userid":"7","title":"Suresh Birthday","start":1357686000,"end":1357686000,"description":"suresh birthday on 9t april","venue":"Bangalore","allDay":true},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-11-28 01:00:00","end":"2012-11-28 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-11-29 01:00:00","end":"2012-11-29 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-11-30 01:00:00","end":"2012-11-30 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-12-01 01:00:00","end":"2012-12-01 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"22","userid":"7","title":"appointment with doctor","start":"2012-12-02 01:00:00","end":"2012-12-02 02:00:00","description":"for dental checkup","venue":"fortis","allDay":false},
{"id":"23","userid":"7","title":"asdfasd","start":1363042800,"end":1363042800,"description":null,"venue":null,"allDay":true},
{"id":"70","userid":"7","title":"asdf","start":1358204400,"end":1358204400,"description":"asdf","venue":"asdf","allDay":true},
{"id":"71","userid":"7","title":"rahj","start":1358895600,"end":1358895600,"description":"","venue":"as","allDay":true},
{"id":"81","userid":"7","title":"cc","start":1356908400,"end":1356908400,"description":"cc","venue":"","allDay":true},
{"id":"82","userid":"7","title":"kk","start":1358722800,"end":1358722800,"description":"","venue":"","allDay":true},
{"id":"83","userid":"7","title":"mm","start":1359327600,"end":1359327600,"description":"","venue":"","allDay":true},
{"id":"84","userid":"7","title":"vv","start":1359068400,"end":1359068400,"description":"","venue":"","allDay":true},
{"id":"85","userid":"7","title":"zz","start":1358463600,"end":1358463600,"description":"zz","venue":"zz","allDay":true},
{"id":"87","userid":"7","title":"qq","start":1358118000,"end":1358118000,"description":"qq","venue":"qq","allDay":true}]

您可以在预期中清楚地看到我有 5 个“id”实例:“22”,但在输出中我只得到一个。

我在这里面临的问题是:-无法保存同一事件的重复实例。

循环结构对我来说似乎没问题,如果我将 echo 语句放入循环中,它会根据重复的细节显示“n”次出现,但如果我将它编码为 json,最终的 json 对象只有事件的最新记录(除了最后重复的事件细节)。

我猜json不允许重复记录,我希望它有重复记录,请建议我,我哪里出错了.. :-)

4

1 回答 1

1

看起来你正在设置$events[]几个相同的状态$eventsArray......为什么不在每个循环开始时重新初始化它:$eventsArray=array()......?

于 2013-01-25T07:11:55.177 回答