javascript - PHP: getting variables for many rows in a databse -


i trying send php variable id thats saved in database page displaying google map markers using javascript. have created list display displayed when map marker clicked in php/html:

$result = mysqli_query($con,"select * places");          while($row = mysqli_fetch_array($result))         {             echo "<div class='place-details' id='place-details' style='display: none'>";             echo "<table class='table'>";             echo "<tr><th>name: </th><td>" . $row['name'] . "</td></tr>";             echo "<tr><th>details: </th><td>" . $row['description'] . "</td></tr>";             echo"</table>";             echo "<td><a href='details.php?id=".$row['id']."' class='btn btn-warning btn-sm'>view</a></td></div>";         } 

in javascript, using clone() display list in each marker:

var places = $("#place-details").clone().show();  google.maps.event.addlistener(markers[i], "click", function () {         infowindow.setcontent(places[0]);         infowindow.open(map, markers[i]);         map.setcenter(marker.getposition());         map.setzoom(10);     }); 

the "id" created automatically , unique key auto increment. problem is, when page loads , event markers clicked, show data first row id, rather each one's own id- displaying information saved in first row only.

update:

for (var in markers) {     markers[i].setmap(null); }  markers[i] = marker; 

and inside function:

place_info.parsedata = function(data) {     ...... } 

you're using places[0]. var places array of elements, , therefore, must loop through elements. i'm assuming var i generated loop, try setcontent(places[i]);.

using places.length upper bound in loop better route.

it's bad practice put same id attribute on multiple elements. use css class , corresponding selector reference multiple elements share common content or properties.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -