Topic
  • No replies
ianhaney
ianhaney
1 Post

Pinned topic XML HELP

‏2012-04-17T21:14:11Z |
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 <?php echo $_POST; ?>


You have searched in the location of <?php echo $_POST; ?>


You have searched for <?php echo $_POST; ?> bedrooms


You have searched for <?php echo $_POST; ?> bathrooms


You have searched for £<?php echo $_POST; ?>


You have searched for £<?php echo $_POST; ?>



Please find your results below
</body>
</html>




<?php
$xml = simplexml_load_file('properties.xml');
foreach($xml->PROPERTY as $row) {
if(strval($row->$REF) == $_POST) {
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) && strlen($_POST) > 0)
$query .= '[ID="'.$_POST';

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

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

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

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

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

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

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

$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) && strlen($_POST) > 0)
$search .= "&PROPERTYTYPE=" . $_POST;

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

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

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

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

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

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

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

if(isset($_POST))
$i=$_POST;
else
$i=1;
if(isset($_POST))
$page=$_POST;
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 = "http://www.for-rent-nerja.com/images/spacer2.jpg" 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;
$bathrooms=mysql_real_escape_string($_POST;
$minprice=mysql_real_escape_string($_POST;
$maxprice=mysql_real_escape_string($_POST;

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

$result = mysql_query($query);
*/
?>