cant make JSON multi level PHP


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

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



- 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|||<?php $con=mysqli_connect("","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); ?>

People are also looking for solutions to the problem: php - How to update table using LOAD INFILE?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.