javascript - Dynamic downloadURL( ) call -


i'm building website has, among others, photo gallery feature. in gallery page, there's map (google) several markers , every marker related specific photo.

i've got 'markers' table in database:

 markers:   id      | name     |  address | lat   | lng | gallery_id _______________________________________________________ 1       | ..       | ....     |..     | ..  | 2    2       | ..       | ....     |..     | ..  | 2  3       | ..       | ....     |..     | ..  | 3 4       | ..       | ....     |..     | ..  | 3 5       | ..       | ....     |..     | ..  | 10 ......................  

all fields populated geolocated data , every row represents specific photo uploaded user, gallery_id, holds id of gallery owns photo.

in gallery page there's javascript build google map:

<script type="text/javascript">      function load() {       var map = new google.maps.map(document.getelementbyid("map"), {         disabledefaultui: true,         scrollwheel: false,         navigationcontrol: false,         maptypecontrol: false,         scalecontrol: false,         maptypeid: google.maps.maptypeid.roadmap       });       var infowindow = new google.maps.infowindow;       var bounds = new google.maps.latlngbounds();        //phpsqlajax-xmlgenerator.php, data database       downloadurl("phpsqlajax-xmlgenerator.php", function(data) {         var xml = data.responsexml;         var markers = xml.documentelement.getelementsbytagname("marker");         (var = 0; < markers.length; i++) {           var name = markers[i].getattribute("name");           var address = markers[i].getattribute("address");           var type = markers[i].getattribute("type");           var point = new google.maps.latlng(               parsefloat(markers[i].getattribute("lat")),               parsefloat(markers[i].getattribute("lng")));           var html = "<b>" + name + "</b> <br/>" + address;           var marker = new google.maps.marker({             map: map,             position: point,             icon: icon.icon,             animation: google.maps.animation.bounce           });           bindinfowindow(marker, map, infowindow, html);           bounds.extend(marker.position);         }         map.fitbounds(bounds);       });     }      function bindinfowindow(marker, map, infowindow, html) {       google.maps.event.addlistener(marker, 'click', function() {         infowindow.setcontent(html);         infowindow.open(map, marker);       });     }      function downloadurl(url, callback) {       var request = window.activexobject ?           new activexobject('microsoft.xmlhttp') :           new xmlhttprequest;        request.onreadystatechange = function() {         if (request.readystate == 4) {           request.onreadystatechange = donothing;           callback(request, request.status);         }       };        request.open('get', url, true);       request.send(null);     }      function donothing() {}   </script>   

i provide downloadurl phpsqlajax-xmlgenerator.php file, build xml file holding markers table data:

<?php //start xml file, create parent node $dom = new domdocument("1.0"); $node = $dom->createelement("markers"); $parnode = $dom->appendchild($node);  // opens connection mysql server $conn = mysqli_connect('localhost', 'root', 'password', 'database'); if (mysqli_connect_errno()) {     printf("connect failed: %s\n", mysqli_connect_error());     exit(); }  //select rows in markers table $query = "         select * `markers` 1; "; $result = mysqli_query($conn, $query);  header("content-type: text/xml");  // iterate through rows while ($row = mysqli_fetch_assoc($result)){   // add xml document node   $node = $dom->createelement("marker");   $newnode = $parnode->appendchild($node);   $newnode->setattribute("name",$row['name']);   $newnode->setattribute("address", $row['address']);   $newnode->setattribute("lat", $row['lat']);   $newnode->setattribute("lng", $row['lng']);   $newnode->setattribute("type", $row['type']); } echo $dom->savexml(); ?>   

everything works fine far and, long there's 1 gallery in database, map , markers correct.
comes problem: need way provide phpsqlajax-xmlgenerator.php gallery_id, in order perform right query since old 1 returns every rows of markers, no matter gallery. thinking put phpsqlajax-xmlgenerator.php code right on top of gallery.php page , generate xml file directly on page, should provide downloadurl function? gallery.php?. way thinking put sort of $_get request in downloadurl parameter, can't find way perform properly.

pass gallery_id url,e.g.:

downloadurl("phpsqlajax-xmlgenerator.php?id=3", function(data) { 

and build sql based on get-parameter:

$id=@intval($_get['id']); if($id<1){   exit(); } $query = 'select * `markers` gallery_id='.$id; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -