2014-05-02 88 views
0

我試圖讓用戶在類似於Google日曆的日曆應用中安排事件。我要做到這一點每3個星期重複的活動,經過2出現(一個或多個)結束重複發生的事件php

我當前的代碼如下:

$week = array('0'=>"Sunday","1"=>"Monday","2"=>"Tuesday","3"=>"Wednesday","4"=>"Thursday","5"=>"Friday","6"=>"Saturday"); 
         $day = $week[$val]; 

$days = array(
    'Monday', 
    'Tuesday', 
    'Wednesday', 
    'Thursday', 
    'Friday', 
    'Saturday', 
    'Sunday', 
); 

    $today = new DateTime($day); 
    //$today = new DateTime('Friday'); //can set specific day if needed 
// print "Today is " . $today->format('l') . "\n"; 

    foreach($days as $day) { 

    $diff = new DateTime($day); 
    $diff = $diff->format('N') - $today->format('N'); 

    if($diff > 0) { 
     //print "$day is $diff days in the future\n"; 
     //print "\n$diff days future\n"; 
     $st=date('Y-m-d H:i:s',strtotime('+'.($diff).' day',strtotime($s))); 
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s))); 
    } 
    elseif($diff < 0) { 
     $diff = abs($diff); 
    // print "$day is $diff days in the past\n"; 
    // print "$diff days fast\n"; 
     $st=date('Y-m-d H:i:s',strtotime('+'.($diff).' day',strtotime($s))); 
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s))); 
    } 
    else { 
    $st=date('Y-m-d H:i:s',strtotime('+'.$recordsave.' day',strtotime($s))); 
    $et=date('Y-m-d H:i:s',strtotime('+'.$date_diff.'day',strtotime($s))); 
    } 
    } 

任何想法的朋友?

回答

0

PHP代碼觸發的唯一方法是用戶正在訪問它。對於這件事我會建議CRON job

您可以設置一個CRON時間表,通過在CRON作業中每3周調用一次PHP頁面來運行特定的代碼行2周。

+0

嘿朋友即時通訊開發像谷歌日曆應用程序,我需要在用戶添加事件後顯示 –

+0

您的問題有點含糊,編輯現在實現您的前提。 –