I am trying to loop through my SQL result with PHP and JavaScript to set markers on a LeafLet Map. The Data contains the name, latitude, longitude and number.
Here is my code:
var ticker = <?php echo mysqli_num_rows($result); ?>;
for ( let i = 0; i < ticker; i++) {
var latitude = <?php echo json_encode($row["latitude"]); ?>;
var longitude = <?php echo json_encode($row["longitude"]); ?>;
var marker = L.marker([latitude, longitude]).addTo(map);
var popup = <?php echo json_encode($row["name"] . " " . $row["number"]); ?>;
marker.bindPopup(popup);
}
It should add two markers, but somehow it only generates one marker with the data from the first entry.