title: Google maps v3 - adding php generated markers by user input
body: <p>Hello i'm trying to make a bus route finder in google maps.</p>
  
  <p>So far i've got a static route to display on the map with the help of google's "Using PHP/MySQL with Google Maps" example.</p>
  
  <p>That works by a php file extracting data from a database and making a xml file, and then the google maps javascript using that xml data to make markers/polyline.</p>
  
  <p>My version: <a href="http://www.ykothari.co.uk/gmap-php/gmap-php.html" rel="nofollow">http://www.ykothari.co.uk/gmap-php/gmap-php.html</a></p>
  
  <p>php code:</p>
  
  <pre><code>&lt;?php
  require("dbserverinfo.php");
  
  function parseToXML($htmlStr) 
  { 
  $xmlStr=str_replace('&lt;','&amp;lt;',$htmlStr); 
  $xmlStr=str_replace('&gt;','&amp;gt;',$xmlStr); 
  $xmlStr=str_replace('"','&amp;quot;',$xmlStr); 
  $xmlStr=str_replace("'",'&amp;#39;',$xmlStr); 
  $xmlStr=str_replace("&amp;",'&amp;amp;',$xmlStr); 
  return $xmlStr; 
  }
  
  // Opens a connection to a MySQL server
  $connection=mysql_connect ($dbserver, $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 bus109;";
  $result = mysql_query($query);
  if (!$result) {
    die('Invalid query: ' . mysql_error());
   }
  
  header("Content-type: text/xml");
  
  // Start XML file, echo parent node
  echo '&lt;?xml version="1.0"?&gt;' . "\n";
  echo '&lt;markers&gt;' . "\n";
  
  // Iterate through the rows, printing XML nodes for each
  while ($row = @mysql_fetch_assoc($result)){
    // ADD TO XML DOCUMENT NODE
    echo '&lt;markers109 ';
    echo 'stopname="' . parseToXML($row['stopname']) . '" ';
    echo 'lat="' . $row['lat'] . '" ';
    echo 'lng="' . $row['lng'] . '" ';
    echo 'service="' . $row['service'] . '" ';
    echo 'stopid="' . $row['stopid'] . '" ';
    echo '/&gt;' . "\n";
  }
  // End XML file
  echo '&lt;/markers&gt;';
  ?&gt;
  </code></pre>
  
  <p>The dataset is like this: <a href="https://spreadsheets.google.com/ccc?key=0AqEGwIC84XiqdGZXM2VMS1VPazdrVExsa0t6TjhPWlE&amp;hl=en&amp;authkey=CMSJup8M" rel="nofollow">https://spreadsheets.google.com/ccc?key=0AqEGwIC84XiqdGZXM2VMS1VPazdrVExsa0t6TjhPWlE&amp;hl=en&amp;authkey=CMSJup8M</a></p>
  
  <p>Now i want to add a search box for user to type in the bus route number that they want to see,  so when they type in say "1" in the search box the php script only gets markers for that routenumber. I assume that the "select * from table" in the php file, is getting the data. Is there a way i can modify this line as the user types it or is there any other way to achieve this? So that the file only fetches the row data for that route and not the entire database as the database about 50,000 entries.</p>
  
  <p>Any links to examples or tutorials are appreciated.</p>