我正在使用以下jQuery日历:http://www.htmldrive.net/items/show/568/astonishing-iCal-like-calendars-with-jQuery
我想使用以下查询填充它:
public function get_upcoming_events()
{
$query = "SELECT * FROM events
WHERE date >= NOW()
ORDER BY date ASC";
return DB::get_results($query);
}
我已经着手用与此类似的格式填充弹出框中的事件信息。
echo '<li><span class="title">'.date('n/j/Y', strtotime($event->date)).' - '.$event->title.'</span>';
echo '<span class="desc"><a href="'.SITE_URL.'/index.php/events/get_event?id='.$event->id.'">Click here for details and to sign up...</a></span></li>';
我现在已经为此下载了一个扩展程序:https://github.com/MrHus/jquery-monthly-ical/tree/根据文档我已将其更改为:
$(document).ready(function()
{
$("#ical").ical({
eventdates: [{"date": "2009-03-21", "title": "My birthday", "desc": "Its my birthday!"},
{"date": "yyyy-01-01", "title": "New Year", "desc": "Its a new year!"},
{"date": "2009-mm-01", "title": "New Month", "desc": "First day of the new month!"},
{"date": "2010-mm-01", "title": "New Month", "desc": "First day of the new month!"},
{"date": "2010-09-01", "title": "Convention", "desc": "September convention."},
{"date": "2010-09-02", "title": "Convention", "desc": "September convention day two."},
{"date": "2010-mm-01", "title": "Towl", "desc": "Dont forget to bring a towl."}
]
});
对此:
$(document).ready(function()
{
$("#ical").ical({
<?php
foreach($events as $event)
{
?>
eventdates: [{"date": "<?php date('Y/m/d') ?>", "title": "<?php $event->title ?>", "desc": "Its my birthday!"},
{"date": "yyyy-01-01", "title": "New Year", "desc": "Its a new year!"},
]
<?php
}
?>
});
如何用上面的方法填充弹出框日历?
答案 0 :(得分:1)
假设get_upcoming_events
处于正常工作状态并且您获取了一个对象数组,则可以使用foreach循环:
// $events is the fetched array
foreach ($events as $event) {
echo '<li><span class="title">'.date('n/j/Y', strtotime($event->date)).' - '.$event->title.'</span>';
echo '<span class="desc"><a href="'.SITE_URL.'/index.php/events/get_event?id='.$event->id.'">Click here for details and to sign up...</a></span></li>';
}