我從數據庫中抓取事件列表,並嘗試將日期與一個標題關聯起來。截至目前我使用的是<dl>
<dt>
<dd>
等。這可能會改變,但我認爲它不會影響我的問題的整體影響。嘗試按日期按事件分組PHP
基本上我想通過查詢搶5個最新事件:
global $wpdb;
$sql = "SELECT e.*, c.*, ese.start_time, ese.end_time
FROM wp_events_detail e
JOIN wp_events_category_rel r ON r.event_id = e.id
JOIN wp_events_category_detail c ON c.id = r.cat_id
LEFT JOIN wp_events_start_end ese ON ese.event_id= e.id
WHERE e.is_active = 'Y'
AND c.category_identifier = 'main'
ORDER BY e.start_date ASC
LIMIT 0, 5";
$results = $wpdb->get_results($sql);
我然後循環他們通過foreach()
:
if(count($results) > 0) {
echo '<div class="calendar-list">';
foreach($results as $event) {
$event_id = $event->id;
$event_name = $event->event_name;
$start_date = $event->start_date;
$start_time = $event->start_time;
$start_time = strtotime($start_time);
$start_time = date('g:ia', $start_time);
$the_time = strtotime($start_date);
$the_day = date('d', $the_time);
$the_month = date('M', $the_time);
echo '<dl class="calendar-day first-child">';
echo '<dt>';
echo '<p class="the-month">' . $the_month . '</p>';
echo '<p class="the-day">' . $the_day . '</p>';
echo '</dt>';
echo '<dd>';
echo '<h4><a href="' . $event_id . '">' . $event_name . '</a></h4>';
echo '<h5><span class="time">' . $start_time . '</span></h5>';
echo '</dd>';
echo '</dl>';
}
echo '</div>';
}
我的主要問題是我需要找出一個將日期相互關聯的方式。例如,6月27日。如果有兩個日期,我想它看起來像:
<div class="calendar-list">
<dl class="calendar">
<dt>
<p class="the-month">JUN</p>
<p class="the-day">27</p>
</dt>
<dd>
<h4><a href="#">Title</a></h4>
<h5><span class="time">Time</span></h5>
</dd>
<dd>
<h4><a href="#">Title</a></h4>
<h5><span class="time">Time</span></h5>
</dd>
</dl>
<dl class="calendar">
<dt>
<p class="the-month">JUN</p>
<p class="the-day">28</p>
</dt>
<dd>
<h4><a href="#">Title</a></h4>
<h5><span class="time">Time</span></h5>
</dd>
</dl>
</div>
我很不確定如何實現這一點。我一直在努力設置和解決一些變數,但一直未能取得理想的結果。
如果有人能指出我該做什麼的正確方向,那將是非常感謝。
謝謝!
滓
這工作得非常好。我不得不調整一些東西來使它適合我的內容,但是這個想法傳達得很好。非常感謝。 – tr3online
我很高興它幫助你! – bfavaretto