snowymasta Posted August 19, 2020 Share Posted August 19, 2020 Hi there, So the below code is working for 1 entry, however there is 2 entries in the database which are different postcodes and I cannot get to show in Google Maps. When I do it without Mysql and just do it direct it works, but really want to do it from MYSQL - both postcodes are valid and tested as well. <?php $sql4 = "SELECT * FROM MK_migration_details"; $result4 = $conn->query($sql4); ?> function initialize() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(40.768505,-111.853244); var myOptions = { mapTypeControl: false, fullscreenControlOptions: false, zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); <?php while($row4 = $result4->fetch_assoc()) { $mig_postcode = $row4["postcode"]; } echo 'addPostCode("'.$mig_postcode.'")'; ?> } I know the issue lies with the PHP / Mysql Loop and the Javascript element 'addpostcode' when I put into the loop does not work, but works for a single address outside the loop. Really appreciate your help guys! Thanks you Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/ Share on other sites More sharing options...
requinix Posted August 19, 2020 Share Posted August 19, 2020 You put the $mig_postcode in the loop. You didn't put the addPostCode in the loop too. Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580754 Share on other sites More sharing options...
snowymasta Posted August 19, 2020 Author Share Posted August 19, 2020 Hey Requinix, thank you for your reply, I thought that too but when I put it in it breaks and the map shows nothing at all. Is there a way I can trouble shoot that when I put it into the loop? Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580758 Share on other sites More sharing options...
requinix Posted August 19, 2020 Share Posted August 19, 2020 If you're outputting multiple addPostCode()s then that part is right. Next place to look would be inside that function... Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580762 Share on other sites More sharing options...
Barand Posted August 19, 2020 Share Posted August 19, 2020 It isn't calling the addPostCode() function, it is just echoing its name ??? echo 'addPostCode("'.$mig_postcode.'")'; Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580764 Share on other sites More sharing options...
snowymasta Posted August 19, 2020 Author Share Posted August 19, 2020 Hi Barand, Understand what your saying so what would you do? as the AddPostcode function is a javascript function? Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580771 Share on other sites More sharing options...
snowymasta Posted August 19, 2020 Author Share Posted August 19, 2020 All sorted, when checking I saw that it was echoing out the addpostcode all on the same line, so added a breaker and put into the loop and working now! Quote Link to comment https://forums.phpfreaks.com/topic/311345-need-help-with-showing-all-postcodes-from-a-db-into-google-maps/#findComment-1580773 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.