我在result:title中收到空值,但在DB中location_end 中有一个值
<?php
$bdd = new PDO('mysql:host;dbname', 'user', 'pass');
$result = $bdd->prepare("SELECT * FROM schedule");
$result->execute();
$event_array = array();
$result->setFetchMode(PDO::FETCH_ASSOC);
while ($record = $result->fetch()) {
$event_array[] = array(
'id' => $record['id'],
'title' => $record['location_end'],
'start' => $record['start_time'],
'end' => $record['end_time'],
);
}
echo json_encode($event_array);
events: {
url: 'http://localhost/FleetManagement/getEvents.php',
type: 'POST',
dataType: 'json',
success: function(){
alert('Get Events Successfull!!');
$('#calendar').fullCalendar('updateEvent',event);
},
error: function(error) {
alert(error);
}
}
结果:标题应该有值,但我收到空
result [{"id":"1","title":null,"start":"2016-01-14 00:15:00","end":"2016-01-14 01:00:00"},{"id":"2","title":null,"start":"2016-01-20 23:45:00","end":"2016-01-20 23:45:00"},{"id":"3","title":null,"start":"2016-01-14 23:45:00","end":"2016-01-14 23:45:00"},{"id":"4","title":null,"start":"2016-01-14 23:45:00","end":"2016-01-14 23:45:00"}]
在结果标题中,我收到空值
您正在尝试使用location_end
字段,但该列不在SQL选择中;
SELECT id, start_time, end_time, status, approval_status FROM schedule
您需要将该列添加到SQL中;
SELECT id, location_end, start_time, end_time, status, approval_status FROM schedule
尝试在json_encode之前打印$event_array
。在我看来,"location_end"包含一些非utf8编码字符。