SQL output use for loop on the array , get only data to the new array and one key name ,data=> mycode:
$sql = "SELECT * FROM Alldata";
if($result = mysqli_query($mysqli,$sql))
{
$rows = array();
$newdata = array();
while($row = mysqli_fetch_assoc($result))
{
$rows[] = $row;
}
}
for($i = 0; $i <= 6; $i++){
$newdata['data'][$i] = $rows[$i]['poo'];
}
echo json_encode($newdata);
output:
Array
(
[data] => Array
(
[0] => 123
[1] => 456
[2] => 789
[3] => 111
[4] => 222
[5] => 333
)
)
{"data":["123","456","789","111","222","333"]}
but I want is like:
Array
(
[0] => Array
(
[data] => 123,456,789,111,222,333
)
)
[{"data":"123,444,555,666,777"}]
How to get this output? thank you!!
implode(',', $yourArray)