I have a problem in creating a JSON file as I need it in my swift app
here is how my DB look like
ID | PICName | PicPath |DeviceName
---------------------------------------------------
1 | NewPIC | new.jpg |ibrahiem
2 | NewPIC | new.jpg |ibrahiem
3 | NewPIC | new.jpg |ibrahiem
4 | NewPIC | new.jpg |Ali
5 | NewPIC | new.jpg |Ali
6 | NewPIC | new.jpg |Ali
I need it to by JSON with 3 levels
DeviceName ---> ID ---- > ( PICName , PicPath)
I just now how to make simple JSON so please correct me if I have a mistake in some commas or brackets
this is my simple code
<?php
$con=mysqli_connect("127.0.0.1","erterte","534234","u13");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$return_arr = array();
$return_arr['xx']= array();
$query = "select * from Products order by deviceid";
$result = mysqli_query($con,$query);
$rows = array();
while($r = mysqli_fetch_array($result)) {
$rows['ID'] = $r['ID'];
$rows['PicPath'] = $r['PicPath'];
$rows['DeviceName'] = $r['DeviceName'];
$rows['PICName'] = $r['PICName'];
array_push($return_arr['xx'],$rows);
}
echo json_encode($return_arr);
mysqli_close($con);
?>