Link to home
Start Free TrialLog in
Avatar of thomaszhwang
thomaszhwangFlag for United States of America

asked on

Put several query result in one JSON file using PHP

I am using a PHP file to generate JSON files.  Now I have three queries.  I generate one JSON file for each of the queries.

I'm just wondering if it is possible to generate one JSON file for all three queries.

Following is the code I use to generate JSON files.  Thanks.

        $arr = array();
	$rs = mysql_query("
		SELECT
			Column
		FROM
			Table;
	");
	while($obj = mysql_fetch_object($rs)) {
		$arr[] = $obj;
	}

Open in new window

Avatar of StingRaY
StingRaY
Flag of Thailand image

Wrap them into another array:

$json = json_encode(array($result1, $result2, $result3));

Open in new window

Avatar of thomaszhwang

ASKER

What's $result1 here?  Same as the $rs in my example?
ASKER CERTIFIED SOLUTION
Avatar of StingRaY
StingRaY
Flag of Thailand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.