my value $viena_salis only brings out the last value(in this case united kingdom) when there are 6 other countries and all of them get the same "plan on visiting "united kingdom"?" I've tried moving var contentString to other places in the loop in hopes of the outcome changing but nothing seems to do it. This code places markers on a google map with numbers how many people have registered from each country, and should place different colored markers depending on the type of user roles(still working on the colored marker part).
$indivitualios_salys is an array of country names.
$google maps is an array of all world countries with coordinates.
I cant figure out what's wrong with it, in my eyes it should just loop js and echo the country name since if($viena_salis==$gm_salis[0]) works with no problems.
if anyone has any ideas to what I did wrong, help would be much appreciated.
P.s I'm still new to php and js.
<?php $i=0;
foreach ($indivitualios_salys as $viena_salis) {
$i++;
foreach ($Google_maps as $gm_salis) {
if ($viena_salis==$gm_salis[0]) {
?>
var contentString = '<div id="content" >'+
'<div id= "siteNotice">'+
'</div>'+
'<div id="bodyContent">'+
'<p>Plan on visisting "<?php echo $viena_salis; ?>"?</p>'+
'<p>Check out our <a href="https://biz4good.co/about/">welcome guide</a> </p>'+
'</div>'+
'</div>';
var infowindow = new google.maps.InfoWindow({
content: contentString});
var <?php echo 'marker'.$i; ?> = new google.maps.Marker({
position: {lat: <?= $gm_salis[1]; ?>, lng: <?= $gm_salis[2]; ?>},
map: map,
icon: <?php
foreach ($remeju_id as $con_id){
foreach ($country_user_id as $user_id_country) {
if($con_id==$user_id_country){
echo 'image_green_blue,';
}
if($con_id!=$user_id_country){
echo 'image_green,';
}
else {
echo 'image_blue,';
}
}
}; ?>
label: { color: '#fff', fontWeight: 'bold', fontSize: '14px', text: '<?php echo $elementCount[$viena_salis]; ?>' }
});
<?php echo 'marker'.$i; ?>.addListener('click', function() {
infowindow.open(map, <?php echo 'marker'.$i; ?>);
});
<?php
}
}
};?>
}
Edit: $indivitualios_salys- looks like:
Array
(
[0] => Aruba
[1] => Lithuania
[2] => Bolivia
[3] => Ukraine
[4] => Bosnia and Herzegovina
[5] => Greece
[9] => United Kingdom
)
$google_maps has all countries but in short it looks like:
Array
(
[0] => Array
(
[0] => Andorra
[1] => 42.546245
[2] => 1.601554
)
[1] => Array
(
[0] => United Arab Emirates
[1] => 23.424076
[2] => 53.847818
)
[2] => Array
(
[0] => Afghanistan
[1] => 33.93911
[2] => 67.709953
)
$indivitualios_salysand$Google_mapslooks like. Also I'd really advise you not to mix PHP blocks within HTML or JS - it makes things unnecessarily hard to read.