Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    New to the CF scene
    Join Date
    Mar 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help adding Drop down menu PHP/MYSQL Ajax call

    I am very new and could totally use a little help with this.

    I have an ajax call that generates xml and is initialized on page load. It works great right now but I need to add in a drop down menu that will allow user to select and change which db it connects to then reinitialize the ajax call and generate new xml from the selected db without page refresh.

    I don't want to dynamically fill the drop down options just pass along the preset option value selected with the url and re-initialize the call.

    Any help will be very much appreciated.. Much respect to the knowledgeable veterans on here that always get it done.. I tried a few things but it just wasn't working so I took it out..

    I figured that I need to ask for some help with this.. Thank In advance for any suggestions you all may have..

    the code is as follows:

    Ajax Call



    Code:
    downloadUrl("scripts/phpsqlajax_genxml.php", function(data) {
              var xml = parseXml(data);
              var markers = xml.documentElement.getElementsByTagName("marker");
            for (var i = 0; i < markers.length; i++) {
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var point = new google.maps.LatLng(lat,lng);
              var address = markers[i].getAttribute("address");
              var name = markers[i].getAttribute("name");
              var html = "<b>"+name+"<\/b><p>"+address;
              var category = markers[i].getAttribute("category");
              var marker = createMarker(point,name,html,category);
             
    
    		}
                 
            hide("sales_leads");
            hide("Clear");
            hide("Direct_Tv");
            makeSidebar();
          });
    	  
    	  
    	   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.responseText, request.status);
            }
          };
    
          request.open('GET', url, true);
          request.send(null);
        }
    
        function parseXml(str) {
          if (window.ActiveXObject) {
            var doc = new ActiveXObject('Microsoft.XMLDOM');
            doc.loadXML(str);
            return doc;
          } else if (window.DOMParser) {
            return (new DOMParser).parseFromString(str, 'text/xml');
          }
        }
    
        function doNothing() {}
    Below is phpsqlajax_genxml.php

    PHP Code:
    <?php  

    require ("dbinfo.php"); 


    // Start XML file, create parent node

    $dom = new DOMDocument("1.0");
    $node $dom->createElement("markers");
    $parnode $dom->appendChild($node); 

    // Opens a connection to a MySQL server

    $connection=mysql_connect ('localhost'$username$password);
    if (!
    $connection) {  die('Not connected : ' mysql_error());} 

    // Set the active MySQL database

    $db_selected mysql_select_db($database$connection);
    if (!
    $db_selected) {
      die (
    'Can\'t use db : ' mysql_error());


    // Select all the rows in the markers table

    $query "SELECT * FROM markers WHERE 1";
    $result mysql_query($query);
    if (!
    $result) {  
      die(
    'Invalid query: ' mysql_error());


    header("Content-type: text/xml encoding=\"utf-8\"");  

    // Iterate through the rows, adding XML nodes for each

    while ($row = @mysql_fetch_assoc($result)){  
      
    // ADD TO 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("category"$row['category']);


    echo 
    $dom->saveXML();

    mysql_free_result ($result);
    mysql_close($connection); 

    ?>
    Below is dbinfo.php

    PHP Code:
    <?php

    $username
    ="xxxxxx";
    $password="yyyyyy";
    $database="zzzzzz";
    ?>
    Last edited by rockitnyc; 03-30-2011 at 08:12 PM.


 

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •