echo json_encode与PHP错误

时间:2011-01-04 14:04:53

标签: php jquery ajax json

知道为什么这不起作用:

$result = mysql_query("SELECT cust_name, description from `projects` where project_no = '".$project_no."'") or die(mysql_error());
            while ($row = mysql_fetch_array($result)) {
                echo json_encode(
                      array("message1" => '".$row['cust_name']."', 
                      "message2" => '".$row['description']."')
                 )
            }

这是错误:Parse error: syntax error, unexpected T_STRING, expecting ')' in /admin/customerfilter.php on line 14

第14行是以“array ...”开头的行

谢谢:)

2 个答案:

答案 0 :(得分:4)

报价过多:

$result = mysql_query("SELECT cust_name, description from `projects` where project_no = '".$project_no."'") or die(mysql_error());
            while ($row = mysql_fetch_array($result)) {
                echo json_encode(
                      array("message1" => $row['cust_name'], 
                      "message2" => $row['description'])
                 )
            }

答案 1 :(得分:3)

echo json_encode(array(
    "message1" => $row['cust_name'],
    "message2" => $row['description'],
));

不要让事情变得更加复杂。