Formatting JSON output in PHP MYSQL -


i trying devbridge autocomplete jquery script work, , oh close. can give me suggestions (dropdown values) need use it's data attribute.

the suggested json formatting as follows:

{     suggestions: [         { value: "united arab emirates", data: "ae" },         { value: "united kingdom",       data: "uk" },         { value: "united states",        data: "us" } ] } 

so far, have managed this:

{ "suggestions": [     "show name 1",     "show name 2" ], "data": [     "1",     "2" ] } 

the code producing output follows:

$reply = array(); $reply['suggestions'] = array(); $reply['data'] = array();  while ($row = $result->fetch_array(mysqli_assoc))//loop through retrieved values {     //add row reply     $reply['suggestions'][]=$row['show_name'];     $reply['data'][]=$row['show_id']; }  //format array json data echo json_encode($reply); 

any suggestions? can't figure out how combine 2 data elements 1 array, let alone prepend them 'value' or 'data'...

while($row = $result->fetch_array(mysqli_assoc)) {  $rec = array();  $rec['value'] = $row['show_name']; $rec['data'] = $row['show_id'];  $payload['suggestions'][] = $rec;  }  echo json_encode($payload); 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -