0

我在使用数据库 JSON 文件和 PHP 时遇到了问题。我包含一个名为messages.php 的脚本,它使用GET id ref 运行。它:

  • 打开数据库连接,
  • 查询当前文章的行列,
  • 使用 php_decode() 解码 json 数据,
  • 并将结果写入页面。

我认为 JSON 处理有问题。JSON 通过一个在相关问题上发布的链接进行验证。

这是一些代码:

<?php

//Prepare a database query, searching for messages
$query = "SELECT * FROM articles WHERE id =".$_GET['id']." LIMIT 1";
echo "<script>alert($query);</script>";

//Create a connection
$con = mysqli_connect('localhost','empty_user','tough_pass','roadsidediner_menu');

//Provide a query and handle
$result = mysqli_query($con,$query);

//Aquire the article row
$row = mysqli_fetch_array($result);

echo $row;

//Store the json data
$rough_json = $row['comments'];

//decode the json file
$json = json_decode($rough_jason,true); //????
var_dump[$json]; //NEVER GETS TO THE VAR DUMP

    $html = "<div class='comment'>";
    $html .= "<h5> said on ";
    $html .= "</h5>";
    $html .= "<p></p></div>";
    echo $html;

$mysqli_close($con);

?>

这些是已知问题: php 脚本在 main.php 中途停止。这发生在上面代码的某个地方,也许是我的 JSON?就是这样:

{
"comments": [
{ "name":"Jon" , 
  "lastName":"Bucks" , 
  "thedate":"May 1, 2013" , 
  "message":"message test one"
},
{ "name":"Joe" , 
"lastName":"Buick" , 
"thedate":"June 6, 2013" , 
"message":"message test two"
},
{ "name":"Jack" , 
"lastName":"Brick" , 
"thedate":"December 2, 2013" , 
"message":"message test three"}
]
}

你是怎么做到的?

4

0 回答 0