I am working on a script to utelise Laterooms XML feed and would like to know how to create dynamic pages.
The script I have so far works but i doesn't create the page dynamically.
Any help would be appreciated.
Thanks,
Simon.
My code so far...
<?php
require("MagicParser.php");
$config_baseHREF = "/stores/hotels/";
function myRecordHandler($item)
{
$productHREF = "". str_replace(" ","",$item["COUNTRY_NAME"]) ."";
$productHREF = strtolower($productHREF);
$productHREF = ereg_replace("[.]", "", $productHREF);
print "<p><a href='". $config_baseHREF ."".$productHREF.".html'>".$item["COUNTRY_NAME"]."</a></p>";
print "<p>".$item["COUNRTY_CODE"]."</p>";
}
print "<h2>Countries</h2>";
$url = "http://xml.laterooms.com/xml_ctry.php3?lang=eng";
MagicParser_parse($url,"myRecordHandler","xml|CTRY_LIST/COUNTRY/");
?>
Hi Simon,
Thank you for your comments!
An immediate problem that I noticed looking at your snippet is that you have not declared $config_baseHREF as global within your myRecordHandler function; therefore it will be being used as an empty string.
You would need....
function myRecordHandler($item)
{
global $config_baseHREF;
...
}
Other than that; you're certainly on the right lines. It's probably best to describe what output you are expecting Vs. what is actually happening; then it should be easier to point towards where you might require changes...
Hi David,
When clicking on a country, this should open a new page and would then display the available cities from that country which would also be pulled from the Laterooms xml feed. Clicking on a city would display the first 10 hotels.
I am also unsure where the variable "q" is defined in this code and how the "dynamic" page is created.
if (isset($_GET["q"]))
{
$productHREF = "countries.php?q=".urlencode($item["COUNTRY_NAME"]);
} else{
Simon.
Hi David,
Why am I able to pull the "hotel_name" and "hotel_star" but not the "url" for this xml using magic parser?
http://xml.laterooms.com/xml_1.php3?pid=p1lat®ion=103&top=1
Hiya,
First thing - autodetect fails on that URL so you will need to specify the format string manually using this code:
MagicParser_parse("http://xml.laterooms.com/xml_1.php3?pid=p1lat®ion=103&top=1","myRecordHandler","xml|HOTEL_SEARCH/HOTEL/");
Click here to see the current page in the demo tool (link will be deleted shortly). Assuming that it's HOTEL_LINK that you're after then if you're using the same format string it should be in the array passed to your recordHandler() function...
If this doesn't help, let me know what XML element you're looking to extract and i'll try and see what's going on...
Hi David,
That's sorted it out, I wasn't adding the entire string (HOTEL_ROOMS/ROOM/LR_RATES/RATE/PRICE) only the last one (PRICE)
Do you have any further tips for creating the dynamic pages we spoke about?
Thanks,
Simon
Hi Simon,
If I understand you correctly; you want to construct a new Laterooms URL from a country name; extracted from a previous Laterooms query? Does that make sense?
If so, can you post example URLs of the first URL (the one that returns a list of countries); and then a second URL that returns a list of cities for a given country.
Then it shouldn't be too hard to write example code that will generate a hyperlink from the output of the first feed to make the second request...
You are along the right lines with $_GET["country"] - it looks like what you will ultimately end up doing is using that variable witin the URL of the second feed that returns the city list; for example:
$url = "http://www.example.com/feed/cities.xml?country=".$_GET["country"];
...and then pass that URL to MagicParser_parse()...
I am posting country codes from a form using
<foxx method="post" action="http://www.gynogapod.co.uk/stores/hotels/results.php">
<select name='country'>
<option value='1'>England</option>
for the country to be selected by the user. Can't figure out what i've missed in order to get the "country" variable into the xml url.
require("includes/MagicParser.php");
$config_baseHREF = "/stores/hotels/";
function myRecordHandler($item)
{
global $config_baseHREF;
$productHREF = "". str_replace(" ","",$item["HOTEL_NAME"]) ."";
$productHREF = strtolower($productHREF);
$productHREF = ereg_replace("[.]", "", $productHREF);
$productHREF = str_replace("-","",$productHREF);
print "".$item["HOTEL_LINK"]." ";
print "<a href='countries/".$productHREF.".php'>".$item["HOTEL_NAME"]."</a><br>";
}
print "<h2>Countries</h2>";
$url = "http://xml.laterooms.com/xml_1.php3xxxxxxxx&ctry=".$_GET["country"]."&city=Manchester&top=10";
MagicParser_parse($url,"myRecordHandler","xml|HOTEL_SEARCH/HOTEL/");
At the very top of results.php add the code:
<?php
print_r($_GET);
print "<br>";
print "Country=".$_GET["country"];
exit();
?>
This will dump the GET variables so that you confirm that country is in there; and further print the value of ?country= in complete isolation from your other code..
Check that out first and see what you get...
I see the error...
Your form code is using the POST method; but you are looking for $_GET["country"]. You need to change one or the other...!
In other words; you need to make your form use method="post", or use $_POST["country"] in results.php
...but not both!
Thanks again David,
The code is now working but it isn't giving the results that I expect. The results are from egypt, but should be from england and the results don't change when the form country is changed. Could it be something to do with clearing memory?
<?php
// print_r($_POST);
// print "<br>";
// print "country=".$_POST["country"];
// exit();
?>
<?php
require("includes/MagicParser.php");
$config_baseHREF = "/stores/hotels/";
function myRecordHandler($item)
{
global $config_baseHREF;
$productHREF = "". str_replace(" ","",$item["HOTEL_NAME"]) ."";
$productHREF = strtolower($productHREF);
$productHREF = ereg_replace("[.]", "", $productHREF);
$productHREF = str_replace("-","",$productHREF);
print "".$item["HOTEL_LINK"]." ";
print "<a href='countries/".$productHREF.".php'>".$item["HOTEL_NAME"]."</a><br>";
}
print "<h2>Countries</h2>";
$url = "http://xml.laterooms.com/xml_1.php3?pid=p1gyn&ctry=".$_POST["country"]."&top=10";
MagicParser_parse($url,"myRecordHandler","xml|HOTEL_SEARCH/HOTEL/");
?>
and the form has now been changed to "post"
That URL is returning hotels in Egypt for any value of ctry... so it doesn't look like a problem with your code.
Best thing to do is work on the XML URL directly into your browser (Internet Explorer displays XML clearly) and work out exactly what parameters you should be passing to the laterooms.com server in order to get back what you want.
Thanks for all your help David.
Hope I can be of some help someday ;)
Have a good weekend.
Simon.
Am I on the right track?
if (isset($_GET["q"]))
{
$productHREF = "countries.php?q=".urlencode($item["COUNTRY_NAME"]);
} else{
}