Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Help

Status
Not open for further replies.

ianhaney

Technical User
Joined
Apr 17, 2012
Messages
1
I created a xml file using excel and wish to diplay the results depending on a user search

I think I have managed to connect to the xml file but is not displaying the results, it says 0 results

Have I done the coding correctly

The code is below

<html>
<body>
You have searched for a&nbsp;<?php echo $_POST['propertytype']; ?>
<br>
You have searched in the location of <?php echo $_POST['location']; ?>
<br />
You have searched for <?php echo $_POST['bedrooms']; ?>&nbsp;bedrooms
<br />
You have searched for <?php echo $_POST['bathrooms']; ?>&nbsp;bathrooms
<br />
You have searched for £<?php echo $_POST['minprice']; ?>
<br />
You have searched for £<?php echo $_POST['maxprice']; ?>
<br><br>
Please find your results below
</body>
</html>
<br><br>

<?php
$xml = simplexml_load_file('properties.xml');
foreach($xml->PROPERTY as $row) {
if(strval($row->$REF) == $_POST['form1']) {
header("Location: {$row->URL}");
die("Header redirect.");
}
}
// If we're still here, then display search results below. I leave this task up to you.
?>

<?php
$query = 'PROPERTIES';

if(isset($_POST['ID']) && strlen($_POST['ID']) > 0)
$query .= '[ID="'.$_POST['ID'].'"]';

if(isset($_POST['PROPERTYTYPE']) && strlen($_POST['PROPERTYTYPE']) > 0)
$query .= '[PROPERTYTYPE="'.$_POST['PROPERTYTYPE'].'"]';

if(isset($_POST['LOCATION']) && strlen($_POST['LOCATION']) > 0)
$query .= '[LOCATION="'.$_POST['LOCATION'].'"]';

if(isset($_POST['BEDROOMS']) && strlen($_POST['BEDROOMS']) > 0)
$query .= '[BEDROOMS="'.$_POST['BEDROOMS'].'"]';

if(isset($_POST['BATHROOMS']) && strlen($_POST['BATHROOMS']) > 0)
$query .= '[BATHROOMS="'.$_POST['BATHROOMS'].'"]';

if(isset($_POST['DESCRIPTION']) && strlen($_POST['DESCRIPTION']) > 0)
$query .= '[DESCRIPTION="'.$_POST['DESCRIPTION'].'"]';

if(isset($_POST['GARDEN']) && strlen($_POST['GARDEN']) > 0)
$query .= '[GARDEN="'.$_POST['GARDEN'].'"]';

if(isset($_POST['PRICE']) && strlen($_POST['PRICE']) > 0)
$query .= '[PRICE="'.$_POST['PRICE'].'"]';

$results = $xml->xpath($query);


echo '<h1>Results ('.((is_array($results) && count($results) > 0) ? count($results) : 0).')</h1>';
if(is_array($results) && count($results) > 0)
{

//This is the number of results to display per page
$limit=4;

//Here we figure out how many pages there are going to be
//Size is the size of the array
$size=count($results);

//Pages is calculated by dividing size by the limit per page
//We use ceil in case it does not divide evenly
$pages=ceil($size/$limit);

$search="";
if(isset($_POST['PROPERTYTYPE']) && strlen($_POST['PROPERTYTYPE']) > 0)
$search .= "&PROPERTYTYPE=" . $_POST['PROPERTYTYPE'];

if(isset($_POST['LOCATION']) && strlen($_POST['LOCATION']) > 0)
$search .= "&LOCATION=" . $_POST['LOCATION'];

if(isset($_POST['BEDROOMS']) && strlen($_POST['BEDROOMS']) > 0)
$search .= "&BEDROOMS=" . $_POST['BEDROOMS'];

if(isset($_POST['BEDROOMS']) && strlen($_POST['BEDROOMS']) > 0)
$search .= "&BEDROOMS=" . $_POST['BEDROOMS'];

if(isset($_POST['BATHROOMS']) && strlen($_POST['BATHROOMS']) > 0)
$search .= "&BATHROOMS=" . $_POST['BATHROOMS'];

if(isset($_POST['DESCRIPTION']) && strlen($_POST['DESCRIPTION']) > 0)
$search .= "&DESCRIPTION=" . $_POST['DESCRIPTION'];

if(isset($_POST['GARDEN']) && strlen($_POST['GARDEN']) > 0)
$search .= "&GARDEN=" . $_POST['GARDEN'];

if(isset($_POST['PRICE']) && strlen($_POST['PRICE']) > 0)
$search .= "&PRICE=" . $_POST['PRICE'];

if(isset($_POST['page']))
$i=$_POST['page'];
else
$i=1;


if(isset($_POST['page']))
$page=$_POST['page'];
else
$page=1;
$start=($page*$limit)-$limit;
$display=array();
while($limit!=0)
{
if($start<$size)
$display[]=$results[$start];
$start++;
$limit--;
}

foreach($display as $property)
{
echo '<div class="price t_color1" > ' . $property->PRICE .' </div> <div class = "t_color1 t_bold"> '. $property->BEDROOMS.$property->PLUS .' ' . $property->STUDIO .' ' .$property->TYPE.' in '.$property->AREA .' </div> <div class = "content1_img float_l">
<a href ="'. $property->URL .'" target="_blank"><img src="'. $property->IMAGE .'"></a> </div> <div class = "content1_text float_l"> <b class="t_color5">Property</b><br /><br /> '. $property->DATAPROPERTY . '</div> <div class = "content2_text float_2"><b class="t_color5">Features</b><br /> <br /> '. $property->DATAFEATURE . '</div> <div class = "left_col float_l"><p><img src = " alt = "" width="500"/></p></div>' ;
}
echo "<div align=\"right\">";
if($i!=1)
echo "<a href=\"?page=" . ($i-1) . "$search\" class=\"t_color1\">Previous Page</a> ";
echo "Page " . $i . " of " . $pages . " ";
if($i!=$pages)
echo "<a href=\"?page=" . ($i+1) . "$search\" class=\"t_color1\">Next Page</a> ";

echo "</div>";
}
else
echo '<h1>No Results</h1>';

?>

<?php
/*
$db=mysql_connect("host", "user", "password");
mysql_select_db("database", $db);

$db = mysql_select_db("database") or die ("Couldnt select database");

?>

<?php
// Query database
$bedrooms=mysql_real_escape_string($_POST['bedrooms'];
$bathrooms=mysql_real_escape_string($_POST['bathrooms'];
$minprice=mysql_real_escape_string($_POST['minprice'];
$maxprice=mysql_real_escape_string($_POST['maxprice'];

$query="SELECT * FROM properties WHERE bedrooms='$bedrooms' AND bathrooms='$bathrooms' AND price >= '$minprice' AND price <= '$maxprice' ORDER BY price DESC";

$result = mysql_query($query);
*/
?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top