0

I want to fetch the records and display as array.select * from album_comment where SUB_ID='$id' displays the row as displayed in image. 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);

I want to fetch the value as

$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}]

3 Answers 3

2

Just put $datas[] instead of $datas in while loop.

$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);
Sign up to request clarification or add additional context in comments.

Comments

1

Change your code like this,

while ($comment_fet = mysql_fetch_assoc($query)) {
    $content = $comment_fet['CONTENT_VALUE'];
    $datas[] = json_decode($content);// capture in array
}
echo $get_like = json_encode($datas);// encode array here

Comments

1

you need to save it all to the array like

$datas = array();
while ($comment_fet = mysql_fetch_assoc($query)) {
    $content = $comment_fet['CONTENT_VALUE'];
    $datas[] = json_decode($content);
}
echo $get_like = json_encode($datas);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.