Im making a list with gyms, with their names,image, team, spots, cp, owner, id, lat, lon.
Now i have it that it gets every query etc. but it gives now many same ids, images, team, etc. but it needs to show all mon_cp mon_owner, mon_id because those mon_* are all different each time.
also it show me the error: "SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 1 column 295 of the JSON data"
$sql = "SELECT
f.id, f.lat, f.lon, f.name, f.url, d.fort_id, d.pokemon_id, d.owner_name, d.cp, s.fort_id, s.team, s.slots_available
FROM forts AS f
LEFT JOIN gym_defenders AS d ON f.id=d.fort_id
LEFT JOIN fort_sightings AS s ON f.id=s.fort_id ORDER BY last_modified DESC";
$result = $mysqli->query($sql);
while($row = $result->fetch_assoc()) {
$url = preg_replace("/^http:/i", "https:", $row['url']);
if($row['team'] == 1){ $team = "mystic";}
if($row['team'] == 2){ $team = "valor";}
if($row['team'] == 3){ $team = "instinct";}
$encode = array("id" => $row['id'],
"name" => $row['name'],
"image" => $url,
"team" => $team,
"spots" => $row['slots_available'],
"mon_cp" => $row['cp'],
"mon_owner" => $row['owner_name'],
"mon_id" => $row['pokemon_id'],
"lat" => $row['lat'],
"lng" => $row['lon']);
echo json_encode($encode, JSON_FORCE_OBJECT);
}
it needs to output the following:
name: Gymname
image: https://images.com/image.png
team: valor
mon_cp: 1234, 233
mon_owner: monowner2000,monowner232
mon_id: 150, 155
lat: 34.67854
lon: 5.054567
echo-ing a complete JSON object each iteration of your result-set. This will make the response invalid