在快速应用程序中创建JSON文件时遇到问题
这是我的数据库的样子
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
我需要3个级别的JSON
DeviceName ---> ID ---->(PICName,PicPath)
我只是现在如何制作简单的JSON,所以如果我在一些逗号或方括号中有误,请更正我
这是我的简单代码
<?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);
?>