Return a JSON object using PHP json_encode() & MySQL to pass to jQuery function

后端 未结 3 1206
攒了一身酷
攒了一身酷 2021-02-02 04:16

I\'m trying to create a json object from MySQL results, but not getting the result I need.

Here is the PHP

$json = array();
$result = m         


        
3条回答
  •  别跟我提以往
    2021-02-02 04:53

    I guess the correct way to do this would be:

    $json = array();
    $result = mysqli_query ($connection, $query);
    while($row = mysqli_fetch_array ($result))     
    {
        $bus = array(
            'latitude' => $row['lat'],
            'longitude' => $row['lng'],
            'icon' => './images/' . $row['busColor'] . '.png'
        );
        array_push($json, $bus);
    }
    
    $jsonstring = json_encode($json);
    echo $jsonstring;
    
    die();
    

提交回复
热议问题