i've only supplied part of the code in the search form. there is a submit button at the end. the db connection details are in a separate inc file.
so can anyone suggest how i can rewrite the code so that i can select the location?
there's two search forms within the site...one is search.inc.php here:
Code: Select all
<?php
require_once("config.inc.php");
if ($xview == "main" || $show_sidebar_always)
{
$searchbox_on_top = 0;
$field_sep = "<br><img src=\"images/spacer.gif\" height=\"2\" width=\"2\"><br>";
}
else
{
$searchbox_on_top = 1;
$field_sep = " ";
}
if($dir_sort)
{
$sortcatsql = "ORDER BY catname";
$sortsubcatsql = "ORDER BY subcatname";
}
else
{
$sortcatsql = "ORDER BY pos";
$sortsubcatsql = "ORDER BY scat.pos";
}
?>
<form action="?" method="get">
<input type="hidden" name="cityid" value="<?php echo $xcityid; ?>">
<input type="hidden" name="lang" value="<?php echo $xlang; ?>">
<input name="search" type="text" size="<?php echo $searchbox_on_top?35:23; ?>" value="<?php echo $_GET['search']; ?>">
<?php
if ($xsubcatid > 0)
{
?>
<?php echo $field_sep; ?>
<select name="cities">
<?php
$sql = "SELECT countryid, cityname AS cityname
FROM $t_cities
WHERE enabled = '1'
ORDER BY countryid";
$cityres = mysql_query($sql);
while ($row=mysql_fetch_array($cityres))
{
echo "{<option value=\"$row[countryid]\">$row[cityname]}</option>\n";
}
?>
</select>
<input type="hidden" name="view" value="ads">
<input type="hidden" name="cities" value="<?php echo $city_url; ?>">
<?php echo $field_sep; ?>
<select name="subcatname">
<?php
$sql = "SELECT subcatid, subcatname AS subcatname
FROM $t_subcats scat
WHERE enabled = '1'
ORDER BY subcatid";
$scatres = mysql_query($sql);
while ($row=mysql_fetch_array($scatres))
{
echo "{<option value=\"$row[subcatid]}\">$row[subcatname]</option>\n";
}
?>
</select>
<input type="hidden" name="view" value="ads">
<input type="hidden" name="subcatid" value="<?php echo $row[subcatname]; ?>">
<?php
if ($xsubcathasprice)
{
?>
<?php echo $field_sep; ?>
<?php echo $xsubcatpricelabel; ?>:
<input type="text" name="pricemin" size="6"><?php echo $lang['SEARCH_TO']; ?>
<input type="text" name="pricemax" size="6">
<?php
}
?>
<?php
foreach ($xsubcatfields as $fldnum=>$fld)
{
if($fld['SEARCHABLE'])
{
?>
<?php echo $field_sep; ?>
<?php echo $fld['NAME']; ?>:
<?php if ($fld['TYPE'] == 'N') { ?>
<input type="text" name="x[<?php echo $fldnum; ?>][min]" size="6"><?php echo $lang['SEARCH_TO']; ?>
<input type="text" name="x[<?php echo $fldnum; ?>][max]" size="6">
<?php } else if ($fld['TYPE'] == "D") { ?>
<select name="x[<?php echo $fldnum; ?>]">
<option value="">- <?php echo $lang['ALL']; ?> -</option>
<?php
foreach ($fld['VALUES_A'] as $v)
{
echo "<option value=\"$v\">$v</option>";
}
?>
</select>
<?php } else { ?>
<input type="text" name="x[<?php echo $fldnum; ?>]" size="23">
<?php } ?>
<?php
}
}
?>
<input type="hidden" name="view" value="ads">
<input type="hidden" name="subcatid" value="<?php echo $xsubcatid; ?>">
<?php
}
elseif ($xcatid > 0)
{
?>
<?php echo $field_sep; ?>
<select name="subcatid">
<option value="0">- <?php echo $xcatname; ?> -</option>
<?php
$sql = "SELECT subcatid, subcatname AS subcatname
FROM $t_subcats scat
WHERE catid = $xcatid
AND enabled = '1'
$sortsubcatsql";
$scatres = mysql_query($sql);
while ($row=mysql_fetch_array($scatres))
{
echo "<option value=\"$row[subcatid]\">$row[subcatname]</option>\n";
}
?>
</select>
<input type="hidden" name="view" value="ads">
<input type="hidden" name="catid" value="<?php echo $xcatid; ?>">
<?php
}
elseif ($xview == "events" || $xview == "showevent")
{
?>
<select><option value="0">- <?php echo $xcatname; ?> -</option></select>
<input type="hidden" name="view" value="events">
<?php
}
else
{
?>
<?php echo $field_sep; ?>
<select name="catid">
<?php
$sql = "SELECT catid, catname AS catname
FROM $t_cats
WHERE enabled = '1'
$sortcatsql";
$catres = mysql_query($sql);
while ($row=mysql_fetch_array($catres))
{
echo "<option value=\"$row[catid]\">$row[catname]</option>\n";
}
?>
<?php if($enable_calendar) { ?><option value="-1"><?php echo $lang['EVENTS']; ?></option><?php } ?>
</select>
<input type="hidden" name="view" value="ads">
<?php
}
?>
<?php
if($xcityid>0)
{
?>
<?php
$sql = "SELECT areaname FROM $t_areas WHERE cityid = $xcityid";
$area_res = mysql_query($sql);
if (mysql_num_rows($area_res))
{
?>
<?php echo $field_sep; ?>
<?php echo $lang['POST_LOCATION']; ?>:
<select name="area">
<option value="">- <?php echo $lang['ALL']; ?> -</option>
<?php
while($area_row = mysql_fetch_array($area_res))
{
echo "<option value=\"$area_row[areaname]\"";
if ($_GET['area'] == $area_row['areaname']) echo " selected";
echo ">$area_row[areaname]</option>";
}
?>
</select>
<?php
}
?>
<?php
}
?>
<button type="submit"><?php echo $lang['BUTTON_SEARCH']; ?></button>
</form>
you can see this search in action on
http://www.asiapropertyshop.co.uk which only displays certain search fields depending on which page you are viewing.
if you look at
http://www.asiapropertyshop.co.uk/?xsubcatid=1, you can see all the search fields from search.inc.
i want to create a separate detailed search page that allows users to choose a location, and the property type aswell as the search fields from search.inc but i am not sure how or why the detail search page isnt working.
i've also re written part of the code for location search here, which im told should work...except it still doesnt
Code: Select all
<?php echo $field_sep; ?>
<select name="cityid">
<?php
$sql = "SELECT countryid, cityname AS cityname
FROM $t_cities
WHERE enabled = '1'
ORDER BY countryid";
$cityres = mysql_query($sql);
$userSelectedCity = $_REQUEST['cityid'];
while ($row=mysql_fetch_array($cityres)) {
if($row[cityname]==$userSelectedCity) {
$selected="selected=\"selected\"";
} else {
$selected="";
}
echo "{<option value=\"$row[countryid]\" $selected>$row[cityname]}</option>\"";
}
?>
</select>
<input type="hidden" name="view" value="ads">
<input type="hidden" name="cityid" value="<?php echo "$xcityid"; ?>">
hope someone can help point me in the right direction. cheers