2014-10-22 403 views
-1

php錯誤
原諒我第一次在php編碼。我正在嘗試將數據從drupal導出到json文件。
研究,我應該缺少「}]或事情的經過,但在9號線或10php解析錯誤:語法錯誤,意外T_VARIABLE我

我找不到10號線是

$items['message/json'] = array(

的錯誤是:

Parse error: syntax error, unexpected T_VARIABLE in line 10

<?php 
/** 
* Implementation of hook_menu() 
*/ 

function message_menu(){ 

$items = array(); 

$items['message/json'] = array(
    'title' => 'Json callback', 
    'page callback' => 'message_json_page', 
    'access arguments' => array('access content'), 
    'type' => MENU_CALLBACK, 

    ); 

return $items; 
} 

/** 
*json call back 
*/ 
function message_json_page() { 

$sql = 「SELECT n.nid , n.title as name, b.body_value as message FROM {node} n INNER   JOIN {field_data_body} b ON n.nid = b.entity.id WHERE n.status = 1 and n.type = :type」 

$result = db_query($sql, array(‘:type’ => ‘message’))->fetchAll(); 

$json_value = json_encode($result); 

print $json_value; 

} 
+2

您還在爲'$ sql'結尾使用分號';',並且在$ sql中使用了引號'''''''''而不是標準引號''''''''' ''和'$結果' – Sean 2014-10-22 04:32:25

+2

那些時髦的語錄會讓你的一天感到沮喪。 – 2014-10-22 04:33:04

+0

你的報價有問題。 – sectus 2014-10-22 04:33:25

回答

1

查詢中您的報價存在一些問題,我已對其進行修改,請現在覈實。

<?php 
    /** 
    * Implementation of hook_menu() 
    */ 

    function message_menu(){ 
    $items = array(); 
    $items['message/json'] = array(
     'title' => 'Json callback', 
     'page callback' => 'message_json_page', 
     'access arguments' => array('access content'), 
     'type' => MENU_CALLBACK, 
     ); 

    return $items; 
    } 

    /** 
    *json call back 
    */ 
    function message_json_page() {   
    $sql = "SELECT n.nid , n.title as name, b.body_value as message 
        FROM {node} n 
         INNER JOIN {field_data_body} b 
          ON n.nid = b.entity.id 
           WHERE n.status = 1 and n.type = :type"; 
     $result = db_query($sql, array(":type" => "message"))->fetchAll(); 
     $json_value = json_encode($result); 
     print $json_value; 
    } 
?> 
+1

謝謝空白頭我用你的代碼,我現在可以打開頁面。但在頁面上的錯誤是在第27行。我會檢查我的SQL數據庫,它看起來像我只需要編輯代碼正在尋找。感謝您的幫助! – cmdace 2014-10-22 20:39:43

相關問題