troubleshooting Question

generate json data with mysql help

Avatar of 3xtr3m3d
3xtr3m3d asked on
PHPMySQL ServerAJAX
5 Comments2 Solutions350 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
CvD

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros