I'm working on a project that has a list of map markers. I'd like to pass data from a php database to values for the map. The mapping section of the code uses javascript. When it's manually entered, the javascript for the markers should look like this:
var locations = [
[
"Place 0",
47.06330, -102.34702,
0,
"",
"",
"",
""],
[
"Place 2",
-27.37025, 133.44892,
1,
"",
"",
"",
"found"],
];
I've tried using echo statements. Here's the combo of mysqli and javascript that I tried...
var locations = [
<?php
while($res = mysqli_fetch_array($result)) {
echo "[";
echo "'".$res['name']."',";
echo "".$res['lat'].", ".$res['lng'].",";
echo "".$res['id'].",";
echo "'',";
echo "'',";
echo "'',";
echo "''],";
}
?>
];
It doesn't give me any errors, but the markers don't show up on the map so it doesn't appear to be working. I'm using mysqli statements elsewhere in the html code and it's connecting properly, so I know that's not the problem. I've looked at several other posts about combining php and javascript, but its still not clear to me how to fix this issue. Any guidance is greatly appreciated!