javascript - Convering json data to Java script array -
i have code above gets data database , place in in json form make readable in java script. results of echo "fiat":["anglia","bronco","capri","cobra","consul","corsair","cortina"],
"land rover":["defender","discovery","discovery 3","discovery 4"] data converted in such way can reference in form var brand=array ();
brand["fiat"]=["anglia","bronco","capri","cobra","consul","corsair","cortina"];
brand["land rover"]=["defender","discovery","discovery 3","discovery 4"];
in java script. 1 know how can this.
$query = mysqli_query($conn,"select * car_models
");
// loop db result while(($result = mysqli_fetch_array($query))) {
// check if id in data array if(!array_key_exists($result['brand'], $data)){ // create array current user $data[$result['brand']] = array(); } // add current race time array (do not need use float)
$data[$result['brand']][] = $result['model'];
}
//json data json_encode($data);
i found solution. added json object in variable , able echo console
` //json data var brandavailable = console.log(brandavailable);
"`
Comments
Post a Comment