php - 获取值作为数组值

标签 php mysql arrays json

我想获取记录并显示为数组。select * from album_comment where SUB_ID='$id' 显示图像中显示的行。 enter image description here

 $sql = "select * from album_comment where SUB_ID='$id'";
$query = mysql_query($sql) or sqlerrorhandler("(" . mysql_errno() . ") " . mysql_error(), $sql, __LINE__);
while ($comment_fet = mysql_fetch_assoc($query)) {
     $content = $comment_fet['CONTENT_VALUE'];
    $datas = json_decode($content);
 }
 echo $get_like = json_encode($content);

我想获取值作为

$datas=[{"name":"hello","commentuser":"desc 259 desc","id":8,"date":"2015-12-09T05:40:12.773Z","displayDate":"Wed Dec 09 2015 11:10:12 GMT+0530 (India Standard Time)8","Like":0,"Unlike":0,"rating":0,"reportAbuse":0},

{"name":"hnnb","commentuser":"hjh ghj  ghj ghj","id":68,"date":"2015-12-09T06:00:44.718Z","displayDate":"Wed Dec 09 2015 11:30:44 GMT+0530 (India Standard Time)68","Like":0,"Unlike":0,"rating":0,"reportAbuse":0},

{"name":"56844","commentuser":"689 498 4849 48","id":45,"date":"2015-12-09T06:03:03.178Z","displayDate":"Wed Dec 09 2015 11:33:03 GMT+0530 (India Standard Time)45","Like":0,"Unlike":0,"rating":0,"reportAbuse":0},

{"name":"dcfg","commentuser":"bbnbvbvbnbb","id":60,"date":"2015-12-09T06:49:10.875Z","displayDate":"Wed Dec 09 2015 12:19:10 GMT+0530 (India Standard Time)60","Like":0,"Unlike":0,"rating":0,"reportAbuse":0}]

最佳答案

只需将 $datas[] 而不是 $datas 放入 while 循环。

$sql = "select * from album_comment where SUB_ID='$id'";
$query = mysql_query($sql) or sqlerrorhandler("(" . mysql_errno() . ")      " . mysql_error(), $sql, __LINE__);
while ($comment_fet = mysql_fetch_assoc($query)) {
    $content = $comment_fet['CONTENT_VALUE'];
    $datas[] = json_decode($content);
}
echo $get_like = json_encode($content);

关于php - 获取值作为数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34172916/

相关文章:

php preg_split 不识别空格

javascript - 关闭浏览器时使用ajax执行查询的解决方案

php - 从 nodejs 向 php 发送请求时输入意外结束

mysql - 在 MyISAM 中删除之前,我应该检查表中是否存在行吗?

ios - 更新/更改数组值(快速)

javascript - 当迭代数组并打印键和值时,还包括 __proto__ 函数,为什么?

php - MySQL:10061 错误但仅通过 PHP

php - codeigniter 选择查询问题

mysql - GET http://localhost:3000/server/server.js net::ERR_ABORTED 404(未找到)

python - 将元组中的列表转换为numpy数组?