Jump to content

Archived

This topic is now archived and is closed to further replies.

BooWho

Advanced search melts brain!

Recommended Posts

I have a series of drop-down menus which make up an advanced search form. I am having major problems understanding how to make the results page work though - I tried researching and testing stuff but no joy whatsoever.

The search form code is straightforward enough:
[code]
<form action="multiresults.php" method="post" name="frmSearch" target="_self" id="frmSearch">
<p>District<br />
<select name="district" id="district" style="width:160px;">
<option value="" selected="selected">All districts</option>
<option value="Nicosia">Nicosia</option>
<option value="Limassol">Limassol</option>
<option value="Larnaca">Larnaca</option>
<option value="Paphos">Paphos</option>
<option value="Famagusta">Famagusta</option>
</select>
</p>
<p>Type<br />
<select name="type" id="type" style="width:160px;">
<option value="" selected>All types</option>
<option value="house">House</option>
<option value="apartment">Apartment</option>
<option value="plot">Plot</option>
<option value="land">Land</option>
<option value="bungalow">Bungalows</option>
<option value="detached">Detached</option>
<option value="semi">Semi-detached</option>
<option value="villa">Villa</option>
<option value="terraced">Terraced</option>
<option value="penthouse">Penthouse</option>
<option value="duplex">Duplex</option>
<option value="maisonette">Maisonette</option>
<option value="groundfloor">Ground floor apartment</option>
<option value="agricultural">Agricultural</option>
<option value="commercial">Commercial</option>
<option value="industrial">Industrial</option>
<option value="mixedzone">Mixed zone</option>
<option value="residential">Residential</option>
</select>
</p>
<p>Bedrooms<br />
<select name="beds" id="beds" style="width:160px;">
<option value="" selected>Any beds</option>
<option value="1">0</option>
<option value="2">1</option>
<option value="3">2</option>
<option value="4">3</option>
<option value="5">4</option>
<option value="6">5</option>
<option value="7">6+</option>
<option value="8">studio</option>
</select></p>
<p>Price from<br />
<select name="price1" id="price1" style="width:160px;">
<option value="" selected>Any price</option>
<option value="10000">10,000</option>
<option value="20000">20,000</option>
<option value="30000">30,000</option>
<option value="40000">40,000</option>
<option value="50000">50,000</option>
<option value="60000">60,000</option>
<option value="70000">70,000</option>
<option value="80000">80,000</option>
<option value="90000">90,000</option>
<option value="100000">100,000</option>
<option value="150000">150,000</option>
<option value="200000">200,000</option>
<option value="250000">250,000</option>
<option value="300000">300,000</option>
<option value="350000">350,000</option>
<option value="400000">400,000</option>
<option value="450000">450,000</option>
<option value="500000">500,000</option>
<option value="550000">550,000</option>
<option value="600000">600,000</option>
<option value="700000">700,000</option>
<option value="800000">800,000</option>
<option value="900000">900,000</option>
<option value="1000000">1,000,000</option>
</select>
</p>
<p>Price to<br />
<select name="price2" id="price2" style="width:160px;">
<option value="" selected>Any price</option>
<option value="10000">10,000</option>
<option value="20000">20,000</option>
<option value="30000">30,000</option>
<option value="40000">40,000</option>
<option value="50000">50,000</option>
<option value="60000">60,000</option>
<option value="70000">70,000</option>
<option value="80000">80,000</option>
<option value="90000">90,000</option>
<option value="100000">100,000</option>
<option value="150000">150,000</option>
<option value="200000">200,000</option>
<option value="250000">250,000</option>
<option value="300000">300,000</option>
<option value="350000">350,000</option>
<option value="400000">400,000</option>
<option value="450000">450,000</option>
<option value="500000">500,000</option>
<option value="550000">550,000</option>
<option value="600000">600,000</option>
<option value="700000">700,000</option>
<option value="800000">800,000</option>
<option value="900000">900,000</option>
<option value="1000000">1,000,000</option>
<option value="1000000+">1,000,000+</option>
</select>
</p>
<p>
<input name="submit" type="image" id="submit" src="images/search.jpg" width="64" height="21" border="0" alt="Search" title="Search" />
</p>
</form>
[/code]

The results page code, well, let's just say that is pretty much useless! But here is the code anyway:

[code]
<?php
$maxRows_rcsResult = 15;
$pageNum_rcsResult = 0;
if (isset($_GET['pageNum_rcsResult'])) {
  $pageNum_rcsResult = $_GET['pageNum_rcsResult'];
}
$startRow_rcsResult = $pageNum_rcsResult * $maxRows_rcsResult;

$colname_rcsResult = "1";
if (isset($_REQUEST['district'])) {
  $colname_rcsResult = (get_magic_quotes_gpc()) ? $_REQUEST['district'] : addslashes($_REQUEST['district']);
}
$colname_rcsResult2 = "1";
if (isset($_REQUEST['type'])) {
  $colname2_rcsResult = (get_magic_quotes_gpc()) ? $_REQUEST['type'] : addslashes($_REQUEST['type']);
}
mysql_select_db($database_connW, $connW);
$query_rcsResult = sprintf("SELECT * FROM realestate WHERE district = '%s' AND type = '%s'", $colname_rcsResult,$colname_rcsResult2);
$query_limit_rcsResult = sprintf("%s LIMIT %d, %d", $query_rcsResult, $startRow_rcsResult, $maxRows_rcsResult);
$rcsResult = mysql_query($query_limit_rcsResult, $connW) or die(mysql_error());
$row_rcsResult = mysql_fetch_assoc($rcsResult);

if (isset($_GET['totalRows_rcsResult'])) {
  $totalRows_rcsResult = $_GET['totalRows_rcsResult'];
} else {
  $all_rcsResult = mysql_query($query_rcsResult);
  $totalRows_rcsResult = mysql_num_rows($all_rcsResult);
}
$totalPages_rcsResult = ceil($totalRows_rcsResult/$maxRows_rcsResult)-1;

$queryString_rcsResult = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_rcsResult") == false &&
        stristr($param, "totalRows_rcsResult") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_rcsResult = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_rcsResult = sprintf("&totalRows_rcsResult=%d%s", $totalRows_rcsResult, $queryString_rcsResult);
?>
[/code]

Perhaps someone knows of a good tutorial I can refer to?
I would appreciate any help.

Share this post


Link to post
Share on other sites
Has anyone got any experience with advanced searches like this? It's new to me, but I'm sure there must be someone out there with the skills to help me - I have a simple form, with dropdowns, which queries one table and then displays any results.

At the moment I am having no luck at all getting this to work, so I would really appreciate some help - it's the last thing left to do on the site now, and it's holding back completion.

Thanks.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.