3xtr3m3d
asked on
need help in making json object
Hi
this is the code i use to generate single json object
result
so there is another query which similar to this and generate exact same kind of output but from a another mysql table
i want to do is combine two results and send to javascript then decode it in javascript
like wrap first result with like table1 second result with table 2 or something
how to do that?
Sorry for the bad english
Regards
this is the code i use to generate single json object
$SQL = mysql_query("SELECT * FROM `receipts` WHERE DATE(date) = '2011-08-03'");
if(mysql_num_rows($SQL ) > 0){
$i=0;
$responce->success = true;
while($SQL_RESULT = mysql_fetch_object($SQL)){
$responce->data[$i]['reciept_no'] = $SQL_RESULT->reciept_no;
$responce->data[$i]['time'] = $SQL_RESULT->date;
$responce->data[$i]['user'] = $SQL_RESULT->user;
$i++;
}
}
else{
$responce->success = false;
$responce->data = '';
$responce->reason = "No Activity...";
}
echo json_encode($responce);
result
{"success":true,"data":[{"reciept_no":"2411","time":"09:33:56 AM","user":"test"},
{"reciept_no":"2412","time":"11:29:01 AM","user":" test "}]}
so there is another query which similar to this and generate exact same kind of output but from a another mysql table
i want to do is combine two results and send to javascript then decode it in javascript
like wrap first result with like table1 second result with table 2 or something
how to do that?
Sorry for the bad english
Regards
More like...
SELECT * FROM `table1` t1, `table2` t2 WHERE t1.DATE(date) = '2011-08-03' and t2.DATE(date) = '2011-08-03' ;
Then add the necessary columns to your $responce variable from table 2.
$responce->data[$i]['recie pt_no'] = $SQL_RESULT->reciept_no;
$responce->data[$i]['time' ] = $SQL_RESULT->date;
$responce->data[$i]['user' ] = $SQL_RESULT->user;
$responce->data[$i]['colum n1'] = $SQL_RESULT->reciept_no;
$responce->data[$i]['colum n2'] = $SQL_RESULT->date;
$responce->data[$i]['colum n3'] = $SQL_RESULT->user;
SELECT * FROM `table1` t1, `table2` t2 WHERE t1.DATE(date) = '2011-08-03' and t2.DATE(date) = '2011-08-03' ;
Then add the necessary columns to your $responce variable from table 2.
$responce->data[$i]['recie
$responce->data[$i]['time'
$responce->data[$i]['user'
$responce->data[$i]['colum
$responce->data[$i]['colum
$responce->data[$i]['colum
If you can join the tables that would be a better way to go...
SELECT *
FROM db.table1 AS t1, db.table2 AS t2
WHERE t1.id = t2.id
AND t1.DATE(date) = '2011-08-03;
SELECT *
FROM db.table1 AS t1, db.table2 AS t2
WHERE t1.id = t2.id
AND t1.DATE(date) = '2011-08-03;
ASKER
hi thanks for reply. not really what i expect. doesnt need to combine query just need to wrap each results so i can get two objects by decoding at javascript end
like
like
table1[{"success":true,"data":[{"reciept_no":"2411","time":"09:33:56 AM","user":"test"},
{"reciept_no":"2412","time":"11:29:01 AM","user":" test "}]}]
table2[{"success":true,"data":[{"reciept_no":"2411","time":"09:33:56 AM","user":"test"},
{"reciept_no":"2412","time":"11:29:01 AM","user":" test "}]}]
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
do json encode only when you have a total array...
say for example...
when you get $response1 from table1 and $response2 from table2 .. .. do something like this...
$final_arr = array("table1" => $response1, "table2" => $response2);
$final_json = json_encode($final_arr);
say for example...
when you get $response1 from table1 and $response2 from table2 .. .. do something like this...
$final_arr = array("table1" => $response1, "table2" => $response2);
$final_json = json_encode($final_arr);
ASKER
Thanks
SELECT * FROM `table1` t1, `table2` t2 WHERE t1.DATE(date) = '2011-08-03';