INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

XML Help

XML Help

(OP)
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 = "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['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);
*/
?>

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close