Avatar of abdesignuk
abdesignuk

asked on 

Add a extra filter to the search

Hey,

Currently I have a property website I am developing and it goes live tomorrow.

It has one issue, and that is when you search a property its fine, but if you select buy then click See All Listings it literally shows all the listings, is there a way to have it where detemining on whether Rent or Buy is selected that it searches for all the properties in that sector that you can rent (if rent was selected) and if buy is selected and you click View all properties it then shows you all the properties in that sector that are for sale.

this would be great if anyone can help me
<?php
include($_SERVER['DOCUMENT_ROOT'] . '/site/admin/includes/config.php');
include("../includes/data.conn.inc.php");
?>
 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
 
<title>Coverwood - Rural Property Search</title>
 
<link rel="stylesheet" type="text/css" href="/site/pages/css/coverwood-main.css" />
 
<link rel="stylesheet" type="text/css" href="/site/pages/lightbox/lightbox.css" />
<script type="text/javascript" src="/site/pages/lightbox/lightbox.js"></script>
<script src = "/site/pages/js/build/yahoo-dom-event/yahoo-dom-event.js" ></script> 
<script src = "/site/pages/js//build/dragdrop/dragdrop-min.js" ></script>
 <!-- Slider source file -->
<script src = "/site/pages/js//build/slider/slider-min.js" ></script>   
<script src="/site/pages/commerical/slider/dhtmlgoodies_slider.js"></script>
 
 
<script type="text/javascript" src="/site/pages/js/flash.js"></script>
<script type="text/javascript">
    var FO = { movie:"/site/pages/flash/banners/rural.swf", width:"504", height:"111",
      majorversion:"6", build:"40" };
	    UFO.create(FO, "flash-banner");
    </script>
	
	<style type="text/css">
	
		.form_widget_amount_slider{
		border-top:1px solid #9d9c99;
		border-left:1px solid #9d9c99;
		border-bottom:1px solid #eee;
		border-right:1px solid #eee;
		background-color:#f0ede0;
		height:3px;
		position:absolute;
		bottom:0px;
		width:200px;
		
 
	}
	</style>
 	
 
<style type="text/css">
 
    #slider-price {
        position: relative;
        background:url(assets/bg-fader.gif) 5px 0 no-repeat;
        height:28px;
        width:328px; 
    }
 
    #slider-thumb {
        position: absolute;
        top: 4px;
    }
    #slider-feet {
        position: relative;
        background:url(assets/bg-fader.gif) 5px 0 no-repeat;
        height:28px;
        width:328px; 
    }
 
    #slider-thumb2 {
        position: absolute;
        top: 4px;
    }
</style>
 
 
 
<script type="text/javascript">
(function() {
    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
        slider, 
        bg="slider-price", thumb="slider-thumb", 
        textfield="pricerange"
 
    // The slider can move 0 pixels up
    var topConstraint = 0;
 
    // The slider can move 200 pixels down
    var bottomConstraint = 200;
 
    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 20;
 
 
    Event.onDOMReady(function() {
 
        slider = YAHOO.widget.Slider.getHorizSlider(bg, 
                         thumb, topConstraint, bottomConstraint);
 
        slider.getRealValue = function() {
            return Math.round(this.getValue() * scaleFactor);
        }
 
        slider.subscribe("change", function() {
 
            var fld = Dom.get(textfield);
 
 
            // use the scale factor to convert the pixel offset into a real
            // value
            var actualValue = slider.getRealValue();
 
            // update the text box with the actual value
            fld.value = actualValue;
 
            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;
 
        });
 
        // Listen for keystrokes on the form field that displays the
        // control's value.  While not provided by default, having a
        // form field with the slider is a good way to help keep your
        // application accessible.
        Event.on(textfield, "keydown", function(e) {
 
            // set the value when the 'return' key is detected
            if (Event.getCharCode(e) === 13) {
                var v = parseFloat(this.value, 10);
                v = (lang.isNumber(v)) ? v : 0;
 
                // convert the real value into a pixel offset
                slider.setValue(Math.round(v/scaleFactor));
            }
        });
        
        Event.on('buy', "change", function(e) {
          if( Dom.get('buy').value == '1' )
          {
            scaleFactor = 20;
          }
          else
          {
            scaleFactor = 25000;
          }
           var fld = Dom.get(textfield);
            // use the scale factor to convert the pixel offset into a real
            // value
            var actualValue = slider.getRealValue();
 
            // update the text box with the actual value
            fld.value = actualValue;
 
            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;
        });
        
       
    });
    
     var Event2 = YAHOO.util.Event,
        slider2, 
        bg2="slider-feet", thumb2="slider-thumb2", 
        textfield2="squarefeet"
 
    // The slider can move 0 pixels up
    var topConstraint2 = 0;
 
    // The slider can move 200 pixels down
    var bottomConstraint2 = 200;
 
    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor2 = 100;
 
 
    Event2.onDOMReady(function() {
 
        slider2 = YAHOO.widget.Slider.getHorizSlider(bg2, 
                         thumb2, topConstraint2, bottomConstraint2);
 
        slider2.getRealValue = function() {
            return Math.round(this.getValue() * scaleFactor2);
        }
 
        slider2.subscribe("change", function(offsetFromStart) {
 
            var fld = Dom.get(textfield2);
 
 
            // use the scale factor to convert the pixel offset into a real
            // value
            var actualValue = slider2.getRealValue();
 
            // update the text box with the actual value
            fld.value = actualValue;
 
            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg2).title = "slider value = " + actualValue;
 
        });
 
        // Listen for keystrokes on the form field that displays the
        // control's value.  While not provided by default, having a
        // form field with the slider is a good way to help keep your
        // application accessible.
        Event2.on(textfield2, "keydown", function(e) {
 
            // set the value when the 'return' key is detected
            if (Event2.getCharCode(e) === 13) {
                var v = parseFloat(this.value, 10);
                v = (lang.isNumber(v)) ? v : 0;
 
                // convert the real value into a pixel offset
                slider2.setValue(Math.round(v/scaleFactor2));
            }
        });
        
        
       
    });
    
})();
</script>
 
 
 
 
</head>
 
<body onload="showrent()">
	<script>
 
function showelement(value)
{
	
	if(value == "1")
	{
		showrent();
	}
	
	else {
		showprice();
	}
 
}
 
function showprice(){
	document.getElementById("price").style.display = "";
	document.getElementById("rent").style.display = "none";
}
 
function showrent()
{
	document.getElementById("price").style.display = "none";
	document.getElementById("rent").style.display = "";
}
</script>
    
    <!-- container begin -->
<div id="container">
    	
        <!--header container begin -->
        <div id="header-container">
     		
            <div id="left-col">
                <div id="logo"><img src="/site/pages/images/rural/coverwood-rural-logo.jpg" alt="Coverwood Commercial" /></div>
        </div>
            
          <div id="right-col">
            
<!-- header-nav begin -->
           	<div id="header-nav">
<?php include("../includes/top-nav.inc.php"); ?>
            </div>	
              
        <!-- flash banner -->
            <div id="flash-banner">
            <p>To view this you require the flash plugin. <a href="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" target="_blank">Get the plugin</a></p>
            </div>
            <!-- flash baner end -->
                
    <?php include("../includes/header-nav.inc.php"); ?>	
              
                   <!-- header-nav end -->
         
            </div>
            
        </div>
        <!--header container end -->
        
        <!-- main-body container begin -->
        <div id="main-body-container">
          <!-- side nav begin -->
         <div id="side-nav">
            <!-- side-nav here -->
             <div id="side-nav-header">
                              <ul class="side-nav">
                                
                                <li class="commercial-txt"><a href="/site/pages/commercial/our-services.php" class="commercial-txt">commercial</a></li>
                                
                                
               </ul>
      </div>
     
 
<div id="side-nav-rural">
                                <ul class="side-nav">
                                
                                <li><a href="/site/pages/rural/our-services.php" class="rural-txt">rural</a></li>
        </ul>
        </div>
         <ul id="rural-items">
                <li><a href="/site/pages/rural/our-services.php" title="Our Services">Our Services</a></li>
                <li><a style="color: #FFFFFF;" href="/site/pages/rural/property-search.php" title="Property Search">Property Search</a></li>
                <li><a href="/site/pages/rural/property-required.php" title="Property Required">Property Required</a></li>
                <li><a href="/site/pages/rural/contact-rural.php" title="Contact Rural">Contact Rural</a></li>
                <li><a href="/site/pages/rural/case-studies.php" title="Case Studies">Case Studies</a></li>
                <li><a href="/site/pages/rural/market-information.php" title="Market Information">Market Information</a></li>
     	 </ul>
 
                           
                            
                            <div id="side-nav-living">
                                <ul class="side-nav">
                                
                                <li><a href="/site/pages/living/our-services.php" class="living-txt">living</a></li>
                              </ul>
                            </div>
                              
                            <div id="side-nav-equestrian">
                           	 <ul class="side-nav">
                                <li><a href="/site/pages/equestrian/our-services.php" title="Equestrian" class="equestrian-txt">equestrian</a></li>
                              </ul>
                            </div>
     
            
            		<div id="side-nav-trees">
                    &nbsp;
                    </div>
                    <div id="side-nav-footer">
                    &copy; Coverwood <?php echo date("Y"); ?>
                    </div>
            
          </div>
          <!-- side nav end -->
 
<!-- main-content begin -->
      <div id="main-content">
            	<!-- main-content-head begin -->
            	<div id="main-content-head">
             <div id="main-content-sector-colour" class="rural"> </div>
       	      
              <div id="breadcrumb-nav">
              	<a href="/site/pages/rural/property-search.php">property search</a> 
			  
			  </div>
            	</div>
                <!-- main-content-head end -->
                
                <div id="main-content-body">
				
                	<div id="body-content">
					
					<?php
if (isset($_GET['pageno'])){
	
	$pageno = $_GET['pageno'];
}else{
	
	$pageno = 1;
}
 
 
					if(isset($_REQUEST['search'])){
					
						$location = mysql_real_escape_string($_REQUEST['location']);
						$rent_per_month = mysql_real_escape_string($_REQUEST['rent_per_month'])*1000;
						$pricerange = mysql_real_escape_string($_REQUEST['pricerange'])*1000;
						$buy = intval($_REQUEST['buy']);
						
						if($location){
							
							$loc = " AND p.location = '".$location."'";
						}else{
							
							$loc = '';
						}
						
						if(isset($_REQUEST['listtype'])){ // RENT
							
							$sql = "SELECT * FROM `property` AS p WHERE p.property_type LIKE '%rural%' ORDER BY p.price DESC";
						}elseif($buy == 1){ // BUY
							
							$sql = "SELECT * FROM `property` AS p WHERE p.price >= '{$rent_per_month}' AND p.sale_type = true AND p.property_type LIKE '%rural%'".$loc." ORDER BY p.price DESC";
						}else{
						
							$sql = "SELECT * FROM `property` AS p WHERE p.price >= '{$pricerange}' AND p.sale_type = false AND p.property_type LIKE '%rural%'".$loc." ORDER BY p.price DESC";
						}
 
 
						
 
						
$numrows = mysql_num_rows(mysql_query($sql));
$rows_per_page = 5;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
if ($pageno < 1) {
   $pageno = 1;
} // if
 
$ending .= ' LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
 
						
$sql .= $ending;
 
 
						$result = mysql_query($sql);
						if($numrows > 0){
											
							echo '<ol>';	
							while($row = mysql_fetch_assoc($result)){
							 
							 # lets make some variables
							 $property_id = $row['property_id'];
							 $search_name = $row['property_name'];
							 $description_display = $row['description'];
							 $location = $row['location'];
							 $property_type = $row['property_type'];
							 
							 // Get image
							$imgRslt = mysql_query("SELECT image_name, image_type FROM property_image WHERE property_id = '$property_id' ORDER BY image_type DESC LIMIT 1");
							$imgRow = mysql_fetch_array($imgRslt);
							if(empty($imgRow)){
								$image = '/site/pages/images/common/img-soon.jpg';
							} else {
								$image = PROPERTY_IMAGE_DIR_URI . '/thumbnails/' . $imgRow['image_name'];
							}
									 
							 # lets show the results
							echo "<li class='search-result'>
							 <h3>$search_name, $location</h3>
							 <div id='$property_id' style='height: 100%; width: 100%;min-height: 107px;'><img src='".$image."' style='margin: 5px;float: left;/><span style='float: right; width: 300px;'>$description_display</span><br />
							 <br />Property Status: ".$row['status']."</div>
							 <br style=clear: both;/>
							 <p><a href=\"./display-property.php?property_id=$property_id
							 \">View this Property</a></p></li><span style='clear: both;'></span>\n";
															 
							// end SQL 
							}
							echo '</ol>';
$string = '';
foreach($_GET as $key => $value){
	
	if($key == 'pageno'){
		}else{
		$string[] = $key.'='.$value;
	}
}
 
$string_ = join('&', $string);
echo "<p><br />Page $pageno of $lastpage with a total amount of $numrows results</p> ";		
?>
<p>
<?php
if ($pageno == 1) {
echo " <p>FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1&$string_'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage&$string_'>PREV</a> ";
}
if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage&$string_'>NEXT</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage&$string_'>LAST</a> </p>";
}
 
						}else{
							echo "<p>Sorry but your search criteria returned no results. Please <a href=\"property-search.php\">click here</a> to redefine your search.</p>";
						}
					}else{
					
?>	
<form action="property-search.php" method="get"><input type="hidden" name="search" value="1" />
<table width="100%" border="0" cellspacing="10" cellpadding="0">
  <tr>
    <td><p>I wish to:</p></td>
    <td><p>
      <select name="buy" onChange="showelement(this.value);">
        <option value="1">Rent</option>
        <option value="0">Buy</option>
      </select>
    </p></td>
  </tr>
  <tr id="price">
    <td><p>Minimum buying price:</p></td>
    <td><p><span id="slider_target"></span>
      &pound;
      <input type="text" name="pricerange" size="7" value="1" /> 
      </p></td>
  </tr>
  <tr id="rent">
    <td><p>Minimum Rent Per Month:</p></td>
    <td><p><span id="slider_target2"></span>
          &pound; <input type="text" name="rent_per_month" size="4" value="4000" />
    </p></td>
  </tr>
 
  <tr>
    <td><p>Location:</p></td>
    <td><p>
      <?php
					$query = mysql_query("SELECT location from property");
					$already = array();
					
					while($postcodes = mysql_fetch_array($query))
					{
						if(!array_key_exists($postcodes['location'], $already) && !empty($postcodes['location']))
						{
							$input .= "<option value='{$postcodes['location']}'>{$postcodes['location']}</option>\n";
						}
						
						$already[$postcodes['location']] = $postcodes['location'];
 
					}
					?>
      <select name="location">
        <option value="0">All locations</option>
        <?=$input?>
      </select>
    </p></td>
  </tr>
  <tr>
    <td align="right" colspan="2"><p>
      <input type="submit" value="Search" /><br /><br />
      <a href='?search&listtype=full&filter=rural'>See All Listings</a>
    </p></td>
  </tr>
</table>
</form><script type="text/javascript">
					form_widget_amount_slider('slider_target',document.forms[0].pricerange,200,0,5000000,"");
					form_widget_amount_slider('slider_target2',document.forms[0].rent_per_month,200,0,4000,"");
					</script>
<?php
 
}
?>
 
               	  </div>
        </div>
                
                <div id="main-content-footer">
                <img src="/site/pages/images/common/main-content-footer-bg.jpg" alt="footer-main" />
                </div>
                
          </div>
            <!-- main-content end -->
            
            <!-- sub-content begin -->
            <div id="sub-content">
            
            		<div id="content-box-container">
            		<div class="content-box-header"></div>
           	        <div class="content-box-main">
           	          <p>"<?php include ("../includes/quotes.inc.php"); ?>"
                     </p>
           	        </div>
           	        <div class="content-box-bottom"></div>
            </div>
            
            <?php include("../includes/right-bar.inc.php"); ?>
          
          </div>
          <!-- sub-content end -->
        
        </div>
  <!-- main-body container end -->
        
     <div id="footer">
     <?php include ("../includes/footer.inc.php"); ?>
     </div>
        
</div>
 
	<!-- container end -->
	
 
 
</body>
</html>

Open in new window

ProgrammingDatabasesWeb Applications

Avatar of undefined
Last Comment
abdesignuk
Avatar of irudyk
irudyk
Flag of Canada image

Per your code at line 500-502, buy field (0=Buy; 1=Rent).
So at line 397-399
}elseif($buy == 1){ // BUY

$sql = "SELECT * FROM `property` AS p WHERE p.price >= '{$rent_per_month}' AND p.sale_type = false AND p.property_type LIKE '%rural%'".$loc." ORDER BY p.price DESC";
 
Line 402
$sql = "SELECT * FROM `property` AS p WHERE p.price >= '{$pricerange}' AND p.sale_type = true AND p.property_type LIKE '%rural%'".$loc." ORDER BY p.price DESC";
Avatar of abdesignuk
abdesignuk

ASKER

that does not change anything it still shows properties for rent in the buy search
Avatar of irudyk
irudyk
Flag of Canada image

Okay, so are you saying that it always shows everything  regardless of what you choose (rent or buy) or that the 'rent' option works and the 'buy' option does not?
What is the field in the property table/query that indicates that the property is a buy or rent?
ASKER CERTIFIED SOLUTION
Avatar of Mark Wills
Mark Wills
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of abdesignuk
abdesignuk

ASKER

Thanks my friend sorted it, and was exactly what you said.
Avatar of vbellis-rdy
vbellis-rdy

abdesignuk - give him the points then ! LOL.
Avatar of abdesignuk
abdesignuk

ASKER

i have
Databases
Databases

Databases are organized collections of data, most commonly accessed through management systems including schemas, tables, queries and processes that allow users to enter and manipulate the information or utilize it in other fashions, such as with web applications or for reporting purposes.

62K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo