我有一个jQuery日历,一天有3个事件。如果任何客户预订了一个事件,我的日历会在我将其提交到SQL数据库后显示。
因此,如果我只在SQL中提交任何日期,我的日历会显示它。这意味着通过PHP
if($date > 0) { echo 'here is result';}
要显示我想要的任何事件,请在我的页面中为特定事件添加以下脚本:{ "EventID": 1, "StartDateTime": new Date(2015,3, 1), "Title": "10am to 2pm", "URL": "username", "Description": "Booked by ", "CssClass": "Event_1" },
现在在我的SQL中,我为所有事件添加了3个事件* 31天= 93行。如果任何数据在sql的id中的任何行的日期字段中找到,我的页面将显示上面的脚本。
为了更清楚,我给出了这个错误的脚本,我想用jQuery和PHP正确地做。
<?php if($id = '1'){if($date > 0){ echo' ?>
{ "EventID": 1, "StartDateTime": new Date(2015,3,<? echo '$date';?>), "Title": "10am to 2pm", "URL": "#", "Description": "Booked by ", "CssClass": "Event_1" },
<?php ';}} ?>
现在我无法理解如何通过jQuery与php做到这一点?在这里,我读了很多文章,但我失败了。
这是我的代码示例:
<?php
include_once('db.php');
global $db;
$result = mysqli_query($db,"SELECT * FROM room ORDER BY id");
if(!$result) {
die("Database query failed: " . mysqli_error());
}
while($row = mysqli_fetch_assoc($result)) {
$id=$row['id'];
$date=$row['date'];
}
?>
<script type="text/javascript">
$().ready(function() {
// others script here
var events = [
{ "EventID": 1, "StartDateTime": new Date(2015,3, 1), "Title": "10am to 2pm", "URL": "username1", "Description": "Booked by ", "CssClass": "Event_1" },}
{ "EventID": 2, "StartDateTime": new Date(2015,3, 1), "Title": "2pm to 6pm", "URL": "username2", "Description": "Booked by ", "CssClass": "Event_2" },
{ "EventID": 3, "StartDateTime": new Date(2015,3, 1), "Title": "6pm to 10pm", "URL": "username3", "Description": "Booked by ", "CssClass": "Event_3" }
// All events
];
});
</script>