cant make JSON multi level PHP

97

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

{-code-2}
989

Answer

- 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("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); ?>

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

Source

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.