I managed to output the column ‘resort’ in the Json array, but I need ‘country’ too, as well as ‘aantal’. Have no idea how to do that. Can someone please help me?
if ($numrows < 1 && strlen($sq) > 3)
{
$sql = "SELECT resort, country, COUNT(image) AS aantal FROM sx_cam
LEFT JOIN sv_orte ON sv_cam.res_id = sv_orte.res_id
WHERE sound=soundex('$sq') and (status < 1) GROUP BY resort order by aantal desc";
$result2 = mysql_query($sql) or die(mysql_error());
$numrows = mysql_num_rows($result2);
$suggest = 2;
}
$items = array();
while($row = mysql_fetch_assoc($result2)){
$items[$row['resort']] = $row['resort'];
}
foreach ($items as $key=>$value) {
echo strtolower($key)."|$value\n";
}
You’re building the array the wrong way. Once you get the array right, it is as simple as making a call to
json_encodeI’m not entirely sure how you want your json to look, but something like this should get you started
Once you get the above code working, you can tweak the PHP array to change the structure of the JSON to suit your needs.