javascript - PHP for-each loop not working? -
my for-each not working. not looping javascript code. please provide code help?
$guy= querymysql("select lat, long members user='$guy'"); while($data2 = mysql_fetch_array($guy)){ $latitude1= $data2['lat']; $longitude1= $data2['long']; echo "<script>function createmarker() { $.gomap.createmarker( { latitude: $latitude1, longitude: $longitude1, animation: google.maps.animation.drop, title: 'current users location', html: { content: '<p>this location $friend</p>', popup: false } } ); }</script>";
you'd need build array in php loop, , provide data javascript. work:
php
<?php $strout = ''; if (sizeof($following)) { foreach ($following $friend) { $friendsloc = querymysql("select homelocation, currentlocation members user='$friend'"); while ($data2 = mysql_fetch_array($friendsloc)) { $latitude1 = $data2['homelocation']; $longitude1 = $data2['currentlocation']; $strout .= '{"lat": '.$latitude1.', "lon": '.$longitude1.'},'; } } } $strout = 'var locations = [' . rtrim($strout,",") . ']'; ?>
javascript:
$(document).ready(function() { // google map centred on john dalton building: $('#map').gomap({ latitude: 53.472342399999995, longitude: -2.2398096, zoom: 12, maptype: 'roadmap', scalecontrol: true }); <?php echo $strout; ?> // add marker: for(var = 0; < locations.length; i++) { $.gomap.createmarker({ latitude: locations[i].lat, longitude: locations[i].lon, animation: google.maps.animation.drop, title: 'current users location', html: { content: '<p>this location </p>', popup: false } }); } });
Comments
Post a Comment