I am getting an extra [] at the end of the json and it is causing me problems. I tried to search why or where these [] are added but couldn't find anything.
so what I need is [{content},{content},{content}] but I am getting [{content},{content},{content}][]
The result should be:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}]
but instead is:
[{"botserialnumber":1,"name":"","phone":null,"bloodpressure":20,"isbreathing":null,"isawake":null,"heartrate":101,"readPhone":null,"readBot":1},{"botserialnumber":4,"name":"ar","phone":"7084","bloodpressure":90,"isbreathing":0,"isawake":0,"heartrate":90,"readPhone":1,"readBot":1},{"botserialnumber":6,"name":"","phone":null,"bloodpressure":1,"isbreathing":null,"isawake":null,"heartrate":5,"readPhone":null,"readBot":1}][]
The code used:
case 'getdata':
$heroes = array();
$stmt = $conn->prepare("SELECT botserialnumber, name, phone, bloodpressure, isbreathing, isawake, heartrate, readPhone, readBot FROM healers");
$stmt->execute();
$stmt->bind_result($botserialnumber, $namen, $phone, $bloodpressure, $isbreathing, $isawake, $heartrate, $readPhone,$readBot);
while($stmt->fetch()){
//pushing fetched data in an array
$temp = [
'botserialnumber'=>$botserialnumber,
'name'=>$namen,
'phone'=>$phone,
'bloodpressure'=>$bloodpressure,
'isbreathing'=>$isbreathing,
'isawake'=>$isawake,
'heartrate'=>$heartrate,
'readPhone'=>$readPhone,
'readBot'=>$readBot
];
//pushing the array inside the hero array
array_push($heroes, $temp);
}
//displaying the data in json format
echo json_encode($heroes);
break;