New in php. I am trying to send JSON data to the front end in a name-value pair. I tried the example I got here The following is a snippet of code that sends data in the format of a JSON name value.
while($stmt->fetch()){ $list = array('id' => $fid, 'name' => $fname); } $stmt->free_result(); $stmt->close(); echo json_encode($list);
I got this on the interface
Object {id: 12, name: "Manisha"}
The problem is that I was expecting an array of objects. The above value is the last value obtained from the SQL query. What changes should I make to this code so that I can get an array of objects. Sort of
[{"id":"1","name":"Kumari"}, {"id":"2","name":"KM"}, {"id":"3","name":"Manisha"}]
Please advice.
source share