Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7429037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:54:21+00:00 2026-05-29T08:54:21+00:00

I want to get values from a database and put them in an XML

  • 0

I want to get values from a database and put them in an XML temp file (for a Google Maps webapp) and then assign them to an input value.

I know how to do it if the query is static, like Select * from markers where 1 but I want to do something like Select * from markers WHERE ID = $id, and this $id is from a POST.

I have an HTML file with JS that calls a PHP archive to get XML and parse it. It works with static queries, but how can I make those queries dynamic? How can I pass that variable from the JS function to my PHP file?

Here’s my code to get the XML:

<?php
    $username="SOMEUSER";
    $password="SOMEPASSS";
    $database="SOMEUSER_marcadoresMapas";

    function parseToXML($htmlStr) 
    { 
        $xmlStr=str_replace('<','&lt;',$htmlStr); 
        $xmlStr=str_replace('>','&gt;',$xmlStr); 
        $xmlStr=str_replace('"','&quot;',$xmlStr); 
        $xmlStr=str_replace("'",'&apos;',$xmlStr); 
        $xmlStr=str_replace("&",'&amp;',$xmlStr); 
        return $xmlStr; 
    } 

    // 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 clave";
    $result = mysql_query($query);
    if (!$result) {
        die('Invalid query: ' . mysql_error());
    }

    header("Content-type: text/xml");

    // Start XML file, echo parent node
    echo '<markers>';

    // Iterate through the rows, printing XML nodes for each
    while ($row = @mysql_fetch_assoc($result)){
        // ADD TO XML DOCUMENT NODE
        echo '<marker ';
        echo 'name="' . parseToXML($row['name']) . '" ';
        echo 'address="' . parseToXML($row['address']) . '" ';
        echo 'lat="' . $row['lat'] . '" ';
        echo 'lng="' . $row['lng'] . '" ';
        echo 'telefono="' . $row['telefono'] . '" ';
        echo 'zona="' . $row['zona'] . '" ';
        echo 'ciudad="' . $row['ciudad'] . '" ';
        echo 'email="' . $row['email'] . '" ';
        echo 'piso="' . $row['piso'] . '" ';
        echo 'tipo="' . $row['tipo'] . '" ';
        echo 'erasmus="' . $row['erasmus'] . '" ';
        echo 'nhabitaciones="' . $row['nhabitaciones'] . '" ';
        echo 'plazas="' . $row['plazas'] . '" ';
        echo 'equipHabita="' . $row['equipHabita'] . '" ';
        echo 'nbanos="' . $row['nbanos'] . '" ';
        echo 'salon="' . $row['salon'] . '" ';
        echo 'cocina="' . $row['cocina'] . '" ';
        echo 'electrodomesticos="' . $row['electrodomesticos'] . '" ';
        echo 'garaje="' . $row['garaje'] . '" ';
        echo 'internet="' . $row['internet'] . '" ';
        echo 'calefaccion="' . $row['calefaccion'] . '" ';
        echo 'sexo="' . $row['sexo'] . '" ';
        echo 'precio="' . $row['precio'] . '" ';
        echo 'superficie="' . $row['superficie'] . '" ';
        echo 'fecha="' . $row['fecha'] . '" ';
        echo 'otros="' . $row['otros'] . '" ';
        echo 'id="' . $row['id'] . '" ';
        echo '/>';
    }

    //echo 'name="' . parseToXML('&','&amp;', $row['name']) . '" ';

    // End XML file
    echo '</markers>';
?>

And here is the JS that calls the PHP file and gets the XML:

function downloadUrl(url, callback) {
  var request = window.ActiveXObject ?
      new ActiveXObject('Microsoft.XMLHTTP') :
      new XMLHttpRequest; //en cierto modo es una API, acepta requests HTTP.

  request.onreadystatechange = function() {
    if (request.readyState == 4) {
      request.onreadystatechange = doNothing;
      callback(request.responseText, request.status);
    }
  };

  request.open('GET', url, true);
  request.send(null);
}

 downloadUrl("phpsqlajax_genxml2.php", function(data) {
    var xml = parseXml(data); 
    var markers = xml.documentElement.getElementsByTagName("marker"); //coge todos los markers
    for (var i = 0; i < markers.length; i++) { //coge los atributos de los markers
      var name = markers[i].getAttribute("name");
      var address = markers[i].getAttribute("address");
      var telefono= markers[i].getAttribute("telefono");
      var precio=markers[i].getAttribute("precio");
      //var type = markers[i].getAttribute("type");
      var point = new google.maps.LatLng( //crea LatLng a partir de Lat Long de los markers
          parseFloat(markers[i].getAttribute("lat")),
          parseFloat(markers[i].getAttribute("lng")));
      var html = "Nombre:" + name + "<br>Direccion:" + address+"<br>Telefono:"+telefono+"<br>Precio:"+precio;
      var marker = new google.maps.Marker({ //posiciona los markers
        map: map,
        position: point
      });
      bindInfoWindow(marker, map, infoWindow, html); //pone la ventana de información
    }
  });
}

What I want to do is something like function downloadUrl(url, callback,id) and send the ID via POST.

Is this possible or which method I Should use?

Thank you very much, sorry for my lack of good explanation.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:54:23+00:00Added an answer on May 29, 2026 at 8:54 am

    On the JavaScript side you can add the third parameter for the downloadUrl() function. And set the open command to use POST instead of GET

    request.open('POST', url, true);
    

    And to send the id with the request

    var params = 'id='+id;
    request.send(params);
    

    On the PHP side catch and filter the incoming request variable. And add it to the query.

    $id = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
    $query = "SELECT * FROM markers WHERE id = {$id}";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get some results from the MySQL database and put them in
I want to update my dropdown list datasource (get the values from the database
Using VB.Net I want to get a all datagrid cell values, then insert into
is there a best practise to get values from a database in java? my
Hi all.. I want to get some information from my database and show into
I want insert in the row from database, array of values as that each
I am fetching some data from database and want to show these values in
Using Access 2003 I want to get a table value from the two databases
Possible Duplicate: Return value from thread I want to get the free memory of
I want to get all values of a set interface in one go as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.