Reputation: 61
So far my JSON output is like this
[{"dateClose":"2012-07-06","countno":"6","cumulative_sumc":"103"}],[{"dateOpen":"2012-05-29","openNo":"73","cumulative_sum":"73"}]
Where in fact I'd like to have it like the below, just in one multidimensional array
[{"dateClose":"2012-07-06","countno":"6","cumulative_sumc":"103","dateOpen":"2012-05-29","openNo":"73","cumulative_sum":"73"}]
I've been using array_merge,array_combine against project1[] and project[] array, but no luck. My sample code is below. Any helps will be very much appreciated.Thanks.
<?php
require_once('mysql.inc.php');
$dbc =@mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD,DB_NAME);
$x="Set @csum := 0";
$q = "
select dateClose, countno, (@csum := @csum + countno) as cumulative_sumc
from dateclose
order by dateClose";
$rx = mysqli_query($dbc, $x);
$r = mysqli_query($dbc, $q);
if (mysqli_num_rows($r) > 0) {
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$project[] = $row;
}}
$y="Set @csum := 0";
$z = "
select dateOpen, openNo, (@csum := @csum + openNo) as cumulative_sum
from dateopen
order by dateOpen";
$rx = mysqli_query($dbc, $y);
$r = mysqli_query($dbc, $z);
if (mysqli_num_rows($r) > 0) {
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
array_push($project, $row);
}}
echo json_encode($project);
?>
Upvotes: 0
Views: 202
Reputation: 5685
Try $project[] = $row;
instead of $project1[] = $row;
in your script to achieve your JSON output.
Upvotes: 1