topical media & game development

talk show tell print

basic-ajax-04-retrieveHotelInformation.php / php



  <?php
   xmlFile = "C:\\inetpub\\wwwroot\\BegAjax\\Chapter4\\hotel.xml";
   HTML = "";
   count = 0;
   dt = simplexml_load_file(xmlFile);
   dom = DOMDocument::load(xmlFile);
   hotel = dom->getElementsByTagName("hotel"); 
  
  foreach(hotel as node) 
  { 
       city = node->getElementsByTagName("City");
       city = city->item(0)->nodeValue;
    
           type = node->getElementsByTagName("Type");
           type = type->item(0)->nodeValue;
           
           name = node->getElementsByTagName("Name");
           name = name->item(0)->nodeValue;
           
           price = node->getElementsByTagName("Price");
           price = price->item(0)->nodeValue;
    
          if ((type == _GET["type"]) && (city == _GET["city"]) )
      {
          HTML = HTML."<br><span>Hotel: ".name."</span><br><span>Price: ".price."</span><br>";
          count++;
          }
  } 
   if (count ==0)
   {
     HTML ="<br><span>No hotels available</span>";
   }
             
    echo "<div id='displayinfo'>".HTML."</div>";   
  ?>
  <html>
  <script type="text/javascript" src="HiddenFrame.js"></script>  
  <body onload="initialize()">            
  </body>
  </html>
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.