I am trying to fetch the list of id's associated with mobile number using following code.
$sql = "SELECT id FROM complaints WHERE mobile=1555521555";
$r = mysqli_query($conn,$sql);
$res = mysqli_fetch_array($r);
$result = array();
array_push($result,array(
"id"=>$res['id']
)
);
header('Content-Type:application/json');
echo json_encode(array("result"=>$result));
mysqli_close($conn);
But it only result me a single id every time as below instead of list of id's
{"result":[{"id":"82925318"}]}
Actual query result is -
How do I get the multiple results in array of arrays format or in multidimensional array? Like below -
{"result":[{"id":"82925318"}, {"id":"82925319"}]}
You need loop to get all data
$result = array();
while($res = mysqli_fetch_array($r))
{
array_push($result,array(
"id"=>$res['id']
)
);
}