2016-04-04 32 views
-1

我收到結果中的空值:冠軍,但在數據庫中有一個在location_end值如何獲取從我的SQL事件 - 完整的日曆

<?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"}] 

回答

0
在結果標題

,我收到空值

你試着到u在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 
+0

對不起,它不是最新的源代碼,我編輯了我的查詢!相同的結果在標題中爲空值 – Dayle

0

嘗試在json_encode之前打印$event_array。 在我看來'location_end'包含一些非utf8編碼字符。

+0

如何刪除非utf8編碼字符? – Dayle

+0

有很多方法:像你的表utf8的設置字符集。在數據插入時設置「SET CHARACTER SET utf8」。當插入數據時你可以使用「utf_encode」&當前端數據顯示時使用「utf_decode」 –

相關問題