We help IT Professionals succeed at work.
Get Started

generate json data with mysql help

3xtr3m3d
3xtr3m3d asked
on
336 Views
Last Modified: 2012-06-21
Hi

This is the sample of data type i need to generate with 2 mysql queries

$obj = array(
				"attr" => array(
								"id" => 1,
								"rel" => "drive"					
							 ),
				"data" => "My Documents",
	
		"children" => array(
		array(
				"attr" => array(
								"id" => 2,
								"rel" => "file"
							),
				"data" => "file1.doc",
				"state" => ""
			 )
	)	
);
		
echo json_encode($obj); 

Open in new window


this block should generate with

				"attr" => array(
								"id" => 1,
								"rel" => "drive"					
							 ),
				"data" => "My Documents",

Open in new window


SELECT id,rel,data FROM tbl_drives ORDER BY id

Open in new window


below block should generate with

		"children" => array(
		array(
				"attr" => array(
								"id" => 2,
								"rel" => "file"
							),
				"data" => "file1.doc",
				"state" => ""
			 )

Open in new window


SELECT id,rel,data FROM tbl_files WHERE parent_id = '$id' ORDER BY id

Open in new window



Any idea how to loop two queries to generate above json data?

Thanks
Comment
Watch Question
Commented:
This problem has been solved!
Unlock 2 Answers and 5 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE