Log in

View Full Version : PHP Search script help



MBCUK
05-02-2012, 02:02 PM
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
// specify url of xml file
$url = "http://xmlfeed.laterooms.com/index.aspx?aid=11657&rtype=4&kword=london";
// get xml file contents
$xml = simplexml_load_file($url);

// loop begins
foreach($xml->hotel as $hotel)
{
// begin new paragraph
echo "<p>";
echo "<img src=".$hotel->images." height=100 width=100><br/>";
echo "<strong>Hotel Name:</strong> ".$hotel->hotel_name."<br/>";
echo "<strong>Hotel City:</strong> ".$hotel->hotel_city."<br/>";
echo "<strong>Prices From:</strong> &pound;".$hotel->prices_from."<br/>";
echo "<strong>Hotel Link:</strong><a href=".$hotel->hotel_link.">click here</a><br/>";
echo "</p>";
// end paragraph
}
// loop ends

?>
</body>
</html>

Hi there, I am trying to create a textbox and button for the user to change the key word on the following line


$url = "http://xmlfeed.laterooms.com/index.aspx?aid=11657&rtype=4&kword=london";

Thankyou for your help in advance

MBCUK
05-02-2012, 02:04 PM
Sorry... the textbox and button should control kword=london and change the word london to whatever the user types in the textbox

Thankyou

keyboard
05-03-2012, 03:41 AM
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php
if(isset($_POST['urlInput'])) {
$urlGet = mysql_real_escape_string($_POST['urlInput']);
$url = "http://xmlfeed.laterooms.com/index.aspx?aid=11657&rtype=4&kword=" . $urlGet;
// specify url of xml file
// get xml file contents
$xml = simplexml_load_file($url);

// loop begins
foreach($xml->hotel as $hotel)
{
// begin new paragraph
echo "<p>";
echo "<img src=".$hotel->images." height=100 width=100><br/>";
echo "<strong>Hotel Name:</strong> ".$hotel->hotel_name."<br/>";
echo "<strong>Hotel City:</strong> ".$hotel->hotel_city."<br/>";
echo "<strong>Prices From:</strong> &pound;".$hotel->prices_from."<br/>";
echo "<strong>Hotel Link:</strong><a href=".$hotel->hotel_link.">click here</a><br/>";
echo "</p>";
// end paragraph
}
// loop ends
} else {
echo '<form aciton="" method="post">';
echo "Url:";
echo '<input type="text" name="urlInput">';
echo '<input type="submit" value="submit">';
echo '</form>';
}
?>
</body>
</html>