我已经创建了一个从数据库运行的Fullcalendar实例。除了星期一和星期四的事件(显示在数据库中,而不出现在日历中)外,其他所有操作都正常。在代码中,一周中的所有天都被相同地对待。怎么会这样 我已经附上了数据库和日历的视图。我还包括了insert.php,这是我认为问题所在的地方
View of calendar View of database
<html>
<body>
<?php
error_reporting(E_ERROR);
ini_set('display_errors', 1);
error_reporting(1);
$con = mysql_connect("127.0.0.1","neil","souhami2");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("fullcalendar", $con);
$date = ($_POST['dowstart']);
$date1 = str_replace('-', '/', $date);
$date = date('Y-m-d',strtotime($date1 . "-1 days"));
$date3 = ($_POST['dowend']);
$date4 = str_replace('-', '/', $date3);
$date2 = date('Y-m-d',strtotime($date4 . "+1 days"));
$error_message = "";
$titleErr = $equalErr = "";
$title = $start = $end = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$title = test_input($_POST["title"]);
$start = test_input($_POST["start"]);
$end = test_input($_POST["end"]);
$dow = test_input($_POST["dow"]);
$color = test_input($_POST["color"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
};
$one = $_POST["dow"][0];
$two = $_POST["dow"][1];
$three = $_POST["dow"][2];
$comma = $_POST["dow"][3];
$four = $_POST["dow"][4];
$five = $_POST["dow"][5];
$six = $_POST["dow"][6];
$comma = $_POST["dow"][7];
$eight = $_POST["dow"][8];
$nine = $_POST["dow"][9];
$ten = $_POST["dow"][10];
$age=array("Mon"=>"1","Tue"=>"2","Wed"=>"3","Thu"=>"4","Fri"=>"5","Sat"=>"6","Sun"=>"0");
if($eight){
$first = $one.$two.$three;
$first = $age[$first];
$second = $four.$five.$six;
$second = $age[$second];
$third = $eight.$nine.$ten;
$third = $age[$third];
$third = $first.$comma.$second.$comma.$third;
$_POST["dow"] = $third;
}
else if($four){
$first = $one.$two.$three;
$first = $age[$first];
$second = $four.$five.$six;
$second = $age[$second];
$second = $first.$comma.$second;
$_POST["dow"] = $second;
}
else if($one){
$first = $one.$two.$three;
echo $one;echo $two;echo $three;
$first = $age[$first];
echo $first;
$_POST["dow"] = $first;
};
$sql="INSERT INTO events (title, start, end, dow, dowstart, dowend, color)
VALUES
('$_POST[title]','$_POST[start]','$_POST[end]','$_POST[dow]','$date','$date2','$_POST[color]')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "1 record added";
header("location: index.html");
mysql_close($con)
?>
</body>
</html>
这是获取事件的process.php:
<?php
include('config.php');
{
$events = array();
$query = mysqli_query($con, "SELECT * FROM events");
while($fetch = mysqli_fetch_array($query,MYSQLI_ASSOC))
{
$e = array();
$e['id'] = $fetch['id'];
$e['start'] = $fetch['start'];
$e['end'] = $fetch['end'];
$e['title'] = $fetch['title'];
$e['dow'] = $fetch['dow'];
$e['ranges'] = [ array("dowstart" => $fetch['dowstart'],"dowend" => $fetch['dowend'])];
$e['color'] = $fetch['color'];
array_push($events, $e);
}
echo json_encode($events);
}
?>
这是index.html的相关部分
$('#calendar').fullCalendar({
events: JSON.parse(json_events),
utc: true,
header: {
left: 'prev,next today',
center: 'title',
right: 'month,agendaWeek,agendaDay'
},
editable: true,
selectable: true,
select: function() {window.location.href = "http://www.villagehall.westerdale.info/booking/"},
droppable: true,
slotDuration: '00:30:00',
eventRender: function(event){
return (event.ranges.filter(function(pixies){
return (event.start.isBefore(pixies.dowend) &&
event.end.isAfter(pixies.dowstart));
}).length)>0;
},
eventReceive: function(event){
var title = event.title;
var start = event.start.format("YYYY-MM-DD[T]HH:mm:SS");
$.ajax({
url: 'process.php',
data: 'type=new&title='+title+'&startdate='+start+'&enddate='+end+'&zone='+zone,
type: 'POST',
dataType: 'json',
success: function(response){
event.id = response.eventid;
$('#calendar').fullCalendar('updateEvent',event);
},
error: function(e){
console.log(e.responseText);
}
});
$('#calendar').fullCalendar('updateEvent',event);
console.log(event);
},