I am trying to get a JSON array form PHP output which fetches multiple values from the database and converts to JSON array. The PHP code is as follows:
php
$result = $conn->query("SELECT dbname FROM users ORDER BY dbname ASC");
//defined second array for dbnames' list
$dblist = array();
while($row = $result->fetch_assoc()){
//array_push($response['dblist'],$row['dbname']);
$dblist = array('name'=>$row['dbname']);
}
$response['dblist'] = $dblist;
echo json_encode($response);
It gives the following output:
JSON
{"dblist":["a","arsod"]}
But, in order to extract values from JSON, the needed array is like:
json
{"dblist":{"name":"a","name":"arsod"}}
how can I achieve this? I want to fetch these values in android app.