You are here:  » Another Global Help


Another Global Help

Submitted by Bangkok Bob on Wed, 2006-08-30 05:01 in

Hi David,

I have been following the Global Help thread with great interest and have tried to modify the code examples to get hotel details from another affiliate XML datafeed. I can get all the hotel data ok except the hotel id which comes from the regions global. I have tried in parse the hotels to use:

<?php
 
print "".$hotel[$region["HOTEL_ID"]]."<br>";
?>
and also:
<?php
 
print "".$key_hotel_id."<br>";
?>
without success. Your helpful advice or pointers how to get the hotel id to display per record would be appreciated.

Best regards,
Bangkok Bob

<?php
  
// Parse the regions start
  
function myRegionHandler($region)
  {
      global 
$regions;
      
$regions[$region["HOTEL_ID"]] = $region["HOTEL_NAME"];
  }
  foreach(
$countries as $key_city_id => $value)
  {
    
$region_url "http://www.precisionreservations.com/PRWebServ/getOtherInformation.asmx/getAllHotelListByCity?city_id=".$key_city_id."";
    
MagicParser_parse($region_url,"myRegionHandler","xml|DATASET/DIFFGR:DIFFGRAM/NEWDATASET/DATASET/");
  }
  
// Parse the regions end
  // Parse the hotels start
  
function myHotelHandler($hotel)
  {
      global 
$regions;
      print 
"".$hotel[$region["HOTEL_ID"]]."<br>"// this does not display
      
print "".$hotel["HOTEL_NAME"]."<br>";
      print 
"".$hotel["STAR_RATING"]."<br>";
      print 
"".$hotel["MIN_RATE"]."<br>";
      print 
"".$hotel["HOTEL_ADDRESS_I"]."<br>";
      print 
"".$hotel["HOTEL_ADDRESS_II"]."<br>";
      print 
"".$hotel["HOTEL_POSTAL_CODE"]."<br>";
      print 
"".$hotel["AREA_NAME"]."<br>";
      print 
"".$hotel["CITY_ID"]."<br>";
      print 
"".$hotel["CITY_NAME"]."<br><br>";
  }
  foreach(
$regions as $key_hotel_id => $value)
  {
      
$hotel_url "http://www.precisionreservations.com/PRWebServ/getHotelInformation.asmx/getHotelInfo?HOTEL_ID=".$key_hotel_id."";
      
MagicParser_parse($hotel_url,"myHotelHandler","xml|DATASET/DIFFGR:DIFFGRAM/NEWDATASET/DATA/");
  }
  
// Parse the hotels end
?>

Submitted by support on Wed, 2006-08-30 08:06

Hi Bob,

I think you've missed the "s" off the end of the region - the global is declared as $regions, so the following line:

print "".$hotel[$region["HOTEL_ID"]]."<br>"; // this does not display

...should actually be:

print "".$hotel[$regions["HOTEL_ID"]]."<br>";

That may fix it provided that your previous code has successfully populated the $regions global.

Cheers,
David.

Submitted by Bangkok Bob on Wed, 2006-08-30 13:14

Hi David,

Thanks for your guidance.

I have changed the code as per your example but the hotel id is still not showing up. New code is this:

<?php
    
// Parse the hotels start
  
function myHotelHandler($hotel)
  {
      global 
$regions;
      print 
"<!-- start record -->";
      print 
"Hotel ID ".$hotel[$regions["HOTEL_ID"]]."<br>";
      print 
"Hotel Name ".$hotel["HOTEL_NAME"]."<br>";
      print 
"Star Rating ".$hotel["STAR_RATING"]."<br>";
      print 
"Room Rate ".$hotel["MIN_RATE"]."<br>";
      print 
"Address 1 ".$hotel["HOTEL_ADDRESS_I"]."<br>";
      print 
"Address 2 ".$hotel["HOTEL_ADDRESS_II"]."<br>";
      print 
"Post Code ".$hotel["HOTEL_POSTAL_CODE"]."<br>";
      print 
"Area Name ".$hotel["AREA_NAME"]."<br>";
      print 
"City ID ".$hotel["CITY_ID"]."<br>";
      print 
"City Name ".$hotel["CITY_NAME"]."<br>";
      print 
"<!-- end record -->";
  }
  foreach(
$regions as $key_hotel_id => $value)
  {
      
$hotel_url "http://www.precisionreservations.com/PRWebServ/getHotelInformation.asmx/getHotelInfo?HOTEL_ID=".$key_hotel_id."";
      
MagicParser_parse($hotel_url,"myHotelHandler","xml|DATASET/DIFFGR:DIFFGRAM/NEWDATASET/DATA/");
  }
  
// Parse the hotels end
?>

which gives this output:

<!-- start record -->
Hotel ID <br>
Hotel Name Landmark Mandarin Oriental Hotel<br>
Star Rating 5<br>
Room Rate 395.0000<br>
Address 1 15 Queen's Road Central, The Landmark, Central<br>
Address 2 <br>
Post Code <br>
Area Name Central <br>
City ID 16808<br>
City Name Hong Kong<br>
<!-- end record -->
<!-- start record -->
Hotel ID <br>
Hotel Name Peninsula Hotel<br>
Star Rating 5<br>
Room Rate 350.0000<br>
Address 1 Salisbury Road, Kowloon<br>
Address 2 <br>
Post Code <br>
Area Name Tsim Sha Tsui<br>
City ID 16808<br>
City Name Hong Kong<br>
<!-- end record -->

Best regards,
Bangkok Bob

Submitted by support on Wed, 2006-08-30 15:16

Hi Bob,

I think you just need to global in $key_hotel_id rather than $regions, as $regions as done its job already - you are using it in the loop. For example:

<?php
    
// Parse the hotels start
  
function myHotelHandler($hotel)
  {
      global 
$key_hotel_id;
      print 
"<!-- start record -->";
      print 
"Hotel ID ".$key_hotel_id."<br>";
      print 
"Hotel Name ".$hotel["HOTEL_NAME"]."<br>";
      print 
"Star Rating ".$hotel["STAR_RATING"]."<br>";
      print 
"Room Rate ".$hotel["MIN_RATE"]."<br>";
      print 
"Address 1 ".$hotel["HOTEL_ADDRESS_I"]."<br>";
      print 
"Address 2 ".$hotel["HOTEL_ADDRESS_II"]."<br>";
      print 
"Post Code ".$hotel["HOTEL_POSTAL_CODE"]."<br>";
      print 
"Area Name ".$hotel["AREA_NAME"]."<br>";
      print 
"City ID ".$hotel["CITY_ID"]."<br>";
      print 
"City Name ".$hotel["CITY_NAME"]."<br>";
      print 
"<!-- end record -->";
  }
  foreach(
$regions as $key_hotel_id => $value)
  {
      
$hotel_url "http://www.precisionreservations.com/PRWebServ/getHotelInformation.asmx/getHotelInfo?HOTEL_ID=".$key_hotel_id."";
      
MagicParser_parse($hotel_url,"myHotelHandler","xml|DATASET/DIFFGR:DIFFGRAM/NEWDATASET/DATA/");
  }
  
// Parse the hotels end
?>

Cheers,
David.

Submitted by Bangkok Bob on Wed, 2006-08-30 19:05

Hi David,

Many thanks for your enlightenment.

Using global $key_hotel_id per your example code the hotel id is ouput in the record display like this:

<!-- start record -->
Hotel ID 69112<br>
Hotel Name Landmark Mandarin Oriental Hotel<br>
Star Rating 5<br>
Room Rate 433.0000<br>
Address 1 15 Queen's Road Central, The Landmark, Central<br>
Address 2 <br>
Post Code <br>
Area Name Central <br>
City ID 16808<br>
City Name Hong Kong<br>
<!-- end record -->

Now the complete working code gets cities per country, hotels per city, and details per hotel parsed from three affiliate XML datafeed URLs. Once again, thanks for your help with this specific example and for the useful code snippets in the Magic Parser Forums.

Best regards,
Bangkok Bob