2010-02-13 61 views
0
$sidebarEvent = '<h4 class="scheduler_sidebar_link"><a href="{*URL*}#date={*DATE_SQL*},mode=month" target="_blank">{*DATE*}</a></h4> 
       <div class="scheduler_sidebar_text">{*TEXT*}</div>'; 

這是我使用的插件的片段。它打印事件日期,然後是描述。我如何修改它以便將所有當天的活動作爲一個列表一起打印?同時顯示當天活動(PHP/MYSQL)

這是在一個單獨的文件中的相關功能:

for ($i = 0; $i < count($events); $i++) { 
     $event = $sidebarEvent; 
     $start_date = str_replace("-", "/", $events[$i]->start_date); 
     $start_date = date_parse($events[$i]->start_date); 
     $start_date = mktime($start_date['hour'], $start_date['minute'], $start_date['second'], $start_date['month'], $start_date['day'], $start_date['year']); 
     $start_date = date(get_option('date_format').' '.get_option('time_format'), $start_date); 
     $event = str_replace("{*URL*}", $url, $event); 
     $event = str_replace("{*DATE*}", $start_date, $event); 
     $event = str_replace("{*DATE_SQL*}", $events[$i]->start_date, $event); 
     $event = str_replace("{*TEXT*}", $events[$i]->text, $event); 
     $final .= $event; 
    } 

感謝

回答

1

可以重組他們在他們的日期值。

$event_groups = array(); 
foreach($events as $event) { 
    if(!isset($event_groups[$event->start_date])) 
    $event_groups[$event->start_date] = array(); 

    $event_groups[$event->start_date] = $event; 
} 

,將讓你與事件的數組的數組組織'date' => Array($event, $event, ...)

從那裏你可以與整個分組列表工作:

foreach($event_groups as $date => $events) { 
    for ($i = 0; $i < count($events); $i++) { 
    $event = $sidebarEvent; 
    $start_date = str_replace("-", "/", $events[$i]->start_date); 
    $start_date = date_parse($events[$i]->start_date); 
    $start_date = mktime($start_date['hour'], $start_date['minute'], $start_date['second'], $start_date['month'], $start_date['day'], $start_date['year']); 
    $start_date = date(get_option('date_format').' '.get_option('time_format'), $start_date); 
    $event = str_replace("{*URL*}", $url, $event); 
    $event = str_replace("{*DATE*}", $start_date, $event); 
    $event = str_replace("{*DATE_SQL*}", $events[$i]->start_date, $event); 
    $event = str_replace("{*TEXT*}", $events[$i]->text, $event); 
    $final .= $event; 
    } 
} 

或獲取事件的列表指定日期:

$list = $event_groups['2010-02-13']; 
相關問題