php - Comments array / loop not looping -


i'm trying loop comments $feed while loop, however, displaying 1 comment, doing wrong? if remove name, loop.
how can name comment while loop? think may solve problem. below current code

$rows = array(); while($feed = mysqli_fetch_assoc($sth)) {         $query_ppimage = "select id, post_id, relation, userid, file_format media userid = '".$feed['userid']."' , relation = 'profile_picture' union select -1 id, '55529055162cf' post_id, 'profile_picture' relation, '0' userid, 'jpg' file_format order id desc limit 1";         $qppimg = $conn->query($query_ppimage);         while($ppimg = mysqli_fetch_assoc($qppimg)) {         $newrow = $feed;         if($feed['relation'] == 'page'){             $query_type = "select name 'page_name' pages id = '".$feed['relation_id']."'";             $typeload = $conn->query($query_type);             while($type = mysqli_fetch_assoc($typeload)) {             $newrow['postto'] = $type;             }         }             $newrow['ppimage'] = $ppimg;         }         $comment_load = "select * media_comments post_id = '".$feed['post_id']."'";         $comments = $conn->query($comment_load);         while($com = mysqli_fetch_assoc($comments)) {                $newrow['comments'] = $com;          }        $rows[] = $newrow;       } print json_encode($rows); 

as per comment, issue facing in each iteration in while loop, overwriting $newrow['comments']. therefore, single value @ end of loop, , final value encounters in while loop.

what want append comment it, using square bracket syntax of php arrays (i.e. appending []).

this done assigning values array, specifying key in brackets. key can omitted, resulting in empty pair of brackets ([]).

$arr[key] = value; $arr[] = value; // key may integer or string // value may value of type 

if $arr doesn't exist yet, created,

that means doing this:

while($com = mysqli_fetch_assoc($comments)) {     $newrow['comments'][] = $com; } 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -