Constructing json array inside while loop

Here is my Query to construct dynamic json

$Query = "SELECT url as src, notes as text, `x-axis` as x, `y-axis` as y, width as width, height as height FROM annotate where `url` ='".$url."' limit 0,10 ";  
$Result = $Connection->query($Query); 
$Data = $Result->fetch_assoc(); 
while($row = $Result->fetch_assoc()){ 
$result[$i]['shapes']['type']= 'rect';
$result[$i]['shapes']['geometry'] =array('x' => $row['x'], 'y'=> $row['y'], 'width' => $row['width'], 'height'=>$row['height'] ); 
echo json_encode($result);

Here is the Expected output and actual output ….

The first one is the console of the data that is expected (i put console as static) the actual output is the second one.

Here is the variable used to console the static output.

var my = {
    src : '<?php echo $_GET['file']?>',
    text : 'Suresh and Gopinath....',
    shapes : [{
        type : 'rect',
        geometry : { x : 0.1825726141078838, y: 0.23756906077348067, width : 0.11602209944751381, height: 0.11618257261410789 }

How can i make the shapes as array like the first one ?

enter image description here

Note :

This questions is the continuation of this one

Source: json

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.