php解析错误:语法错误,意外T_VARIABLE i

时间:2014-10-22 04:28:12

标签: php

php错误
请原谅我第一次在php编码。我试图将数据从drupal导出到json文件 经过研究,我应该失踪"}]或其他东西,但我在第9行或第10行找不到它。

第10行是

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

错误是:

  

解析错误:语法错误,第10行意外的T_VARIABLE

<?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 个答案:

答案 0 :(得分: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;
    }
?>