I want to achieve this output in php.
[ { "id": 1388534400000, "author": "Pete Hunt", "text": "Hey there!" }, { "id": 1420070400000, "author": "Paul O’Shannessy", "text": "React is *great*!" } ] I have a while loop in my backend below.
$pull = "SELECT * FROM mydb"; $result = $con->query($pull); while($row = $result->fetch(PDO::FETCH_ASSOC)) { $json['id'] = $row['id']; $json['author'] = $row['author']; $json['text'] = $row['text']; } echo json_encode($json); It only returns the last row in the database, and I want to display them all.
Thank you.
$json['id'] = $row['id']; $json['author'] = $row['author']; $json['text'] = $row['text'];with$json[] = $row;