<?php
/*

  Retrieve a city and state from a US zipcode.

  Based on example in http://www.webpasties.com/xmlHttpRequest/ by Bill Bercik

  Modified Aug 2005 by Chris Wallace:
        XML returned for all codes starting with the input code
    Additional result element
    Conformance with local standards:
        included connection parameters
        return record as object
        use print 
 */


include "zipdb.php";

  
header('Content-Type: text/xml'); 
  print 
'<?xml version="1.0" standalone="yes"?>';
  print 
'<result>';


  
$zipcode $_REQUEST['zipcode']; 
  if (
strlen($zipcode) >1) {   //  1 digit takes too long to generate
     
$query "select * from zipcodes where zipcode like '$zipcode%' order by zipcode";
     
$table mysql_query($query);
     while (
$result mysql_fetch_object($table)) {
        print 
"<zip><zipcode>{$result->zipcode}</zipcode><city>{$result->city}</city><state>{$result->state}</state></zip>";
     }
  }
  print 
'</result>';

?>