Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Script fetching only first row of address field from the MySQL database
    primarykey
    data
    text
    <p>I am building a page where addresses are being fetched from database and displaying all locations, but the code is only showing first address field from the database. i have even searched google, and all related questiong, but nothing seems to be working.</p> <p>As output i am getting first location in the address field, and that location is being displayed on the google map. what i need to do is to fetch all rows of addresses from address field in the database and display them on google map(multiple markers).</p> <p>is there any way so that i can fetch all the addresses and store them in an array in the database and display those addresses from ' var address ' on the google map.</p> <p>could any body please help i am new to this concept.</p> <pre><code> &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="content-type" content="text/html; charset=UTF-8" /&gt; &lt;title&gt;Google Maps Multiple Markers&lt;/title&gt; &lt;? error_reporting(0); include('dbcon.php'); $result = mysql_query("SELECT address FROM markers"); $new_array = array(); while ($row = mysql_fetch_assoc($result)) { $new_array[] = $row['address']; } $add_js = json_encode( $new_array ); ?&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"&gt;&lt;/script&gt; &lt;script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="map" style="width: 500px; height: 400px;"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; var side_bar_html = ""; var icon1 = "prop.png"; var icon2 = "build.png"; var locations = &lt;?php echo $add_js ?&gt;; //alert(locations); function geocodeAddress(i) { geocoder.geocode( { 'address' : locations[i] }, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); createMarker(results[0].geometry.location, i); } else { alert('Geocode was not successful for the following reason: ' + status); } }); } function createMarker(latlng,i) { var marker = new google.maps.Marker({ map : map, icon : icon1, position : latlng }); //add info window google.maps.event.addListener(marker, 'mouseover', function() { marker.setIcon(icon2); infowindow.setContent(locations[i]); infowindow.open(map, marker); title: 'Property!' }); google.maps.event.addListener(marker, 'mouseout', function() { marker.setIcon(icon1); infowindow.setContent(locations[i]); infowindow.close(map, marker); title: 'Property!' }); //end of adding info window return marker; } var map = new google.maps.Map(document.getElementById('map'), { zoom : 10, center : new google.maps.LatLng(28.6139, 77.2089), mapTypeId : google.maps.MapTypeId.ROADMAP }); var infowindow = new google.maps.InfoWindow({ size: new google.maps.Size(150,50)}); var geocoder = new google.maps.Geocoder(); for (var i = 0; i &lt; locations.length; i++) { geocodeAddress(i); }//end of for loop &lt;/script&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload