从数据库填充完整的日历javascript中的事件 [英] Populating events in full calender javascript from the database

查看:169
本文介绍了从数据库填充完整的日历javascript中的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 codeigniter 在php中预订系统。现在我想填充事件在完整的日历取决于我从数据库中获取的值。

I am making a booking system in php using codeigniter. Now I want to populate the events in full calender depending on the value I am fetching from the database.

我的代码:

<script src='<?php echo base_url();?>assets/fullcalendar/fullcalendar.min.js'></script>

<?php
    $var=0;
    foreach($query->result() as $row) {
        $var++;
        $booking_date = $row->booking_date;
        $booking_start_time = $row->booking_start_time;
     }
?>
<script>
$(document).ready(function() {
    // page is now ready, initialize the calendar...
    var booking_date = '<?php echo $booking_date; ?>';
    var booking_start_time = '<?php echo $booking_start_time; ?>';
    $('#calendar').fullCalendar({
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek,agendaDay'
        },

        events: [{
            title: 'House Cleaning',
            start: booking_date + 'T' + booking_start_time,
            allDay: false
        }]

    });
});
</script>

使用上面的方法我可以得到填满完整日历的最后一个记录。我想将从数据库获取的每个记录填充到完整日历 js 。我如何去做。

Using above I am able get the last record populated on the full calender. I want to populate each record fetched from the database to the full calender js. How do I go about it.

感谢您提前表示歉意,如果我不太明白,但我随时准备根据问题进一步解释。

Thanks in advance and apologies if I am being vague but I am always ready to explain further based on the question.

感谢,

推荐答案

在您的PHP中构建数组,并在javascript中将其格式化为json。将格式化的json传递给事件属性,如下所示:

Build an array in your php and format it as json in your javascript. Pass the formatted json to the event property like this :

events: buildRecordsToJson(calendar_records)


function buildRecordsToJson(calendar_records){
    var employees = [];
    for(var record in calendar_records) {

        var item = calendar_records[record];

        employees.push({ 
            "title"  : "Case # " + item.case_number,
            "record" : item.id,
            "start"  : item.case_due_date 
        });
    }

    return employees;
}

编辑:

假设这是你的结果

$result=mysqli_query($con,$sql);

迭代数据库中的结果集并将其推送到主数组。

Iterate the result sets from your database and push it to the main array.

$list = array();
while ($row = mysqli_fetch_row($result))
{ 
    $entry = array();
    $entry["booking_date"] = $row["booking_date"];
    $entry["booking_start_time"] = $row["booking_start_time"];
    array_push($list,$entry);
}
mysqli_free_result($result);

将$ list数组返回给您的javascript,并将其数据格式化为json可能不是必需的)。

Return $list array to your javascript and feed it to your calendar events after you formatted it to json (might not be necessary).

这篇关于从数据库填充完整的日历javascript中的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆