How can I format the code below to create a json array separated by commas in a php while loop? The json returned cannot be decoded again since it seems invalid
<?php //database config
$rtv = mysqli_query($link, "SELECT * FROM ".$datatable." WHERE productid='".$id."' ");
while($bld =mysqli_fetch_assoc($rtv)){
$date = $bld["timestamp"];
$data = [];
$data[] =[
"requestId" => $requestid,
"Service" => $service,
"Date" => $date
];
echo json_encode($data, JSON_PRETTY_PRINT);
What I get is
[
{
"Id": "90223-1475789-2",
"Service": "Maintenance",
"Date": "2021-06-30 23:07:15"
}
][
{
"Id": "90223-1475789-2",
"Service": "Maintenance",
"Date": "2021-06-30 23:07:15"
}
]
instead of desired format which is
[
{
"Id": "90223-1475789-2",
"Service": "Maintenance",
"Date": "2021-06-30 23:07:15"
},
{
"Id": "90223-1475789-2",
"Service": "Maintenance",
"Date": "2021-06-30 23:07:15"
}
]