Hi David
I'd like to implement a multiple choice search using drop down boxes but unsure how to do it.
ie I would have drop down boxes for: colour / style / material / brand
TIA
Hi David
search.php sent :)
>>Assuming you've added "colour" as a field to your site
I'd also like to search by price range?
Cheers
---------
Jill
Hi Jill,
No problem - price range is in fact already built it just needs to be added to the form - I'll return your file with the mods and sample form...
Cheers,
David.
--
PriceTapestry.com
Hi David,
I've added a new filter option, and whilst the various filter options appear, it doesn't actually filter anything and simply returns the same results. Here is the code I used;
$sql1 = "SELECT DISTINCT(platform) FROM `".$config_databaseTablePrefix."products` WHERE ".$where." AND platform <> '' ORDER BY platform";
if (database_querySelect($sql1,$rows1))
{
print "<label form='bf'>By platform:</label><br />";
print "<select style='width:150px;' id='bf' name='platformFilter'>";
print "<option value=''>All</option>";
foreach($rows1 as $row)
{
$selected = ($_GET["platformFilter"]==$row["platform"]?"selected='selected'":"");
print "<option value='".htmlentities($row["platform"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["platform"]."</option>";
}
print "</select>";
print "<br /><br />";
}
Thanks in advance.
Hello Marcus,
The drop-down code added looks fine, but it sounds like the corresponding filter handling code in search.php is not yet in place. In that file; duplicate all sections of code from one of the existing filters, e.g. categoryFilter for the new platformFilter; for example, at line 17 add:
$platformFilter = ($_GET["platformFilter"]?$_GET["platformFilter"]:"");
...at line 57, add:
if ($platformFilter)
{
$priceWhere .= " AND platform = '".database_safe($platformFilter)."' ";
}
...at line 273 add:
if ($platformFilter)
{
$sortHREF .= "platformFilter=".urlencode($platformFilter)."&";
}
...and finally at line 357 add:
if ($platformFilter)
{
$sort .= "&platformFilter=".urlencode($platformFilter);
}
Hope this helps!
Cheers,
David.
--
PriceTapestry.com
Thanks David, it now seems to be working on some occasions, but on others not all correct results are being returned, or the filter option isn't there when it should be.
For the sake of transparency, I have basically replaced the Brand filter with the Platform one. Could this be an issue anywhere?
Thanks,
Marc.
Hi,
The first stage would be to implement version of search.php from the sidebar filters modification which is available on the more downloads page. I know you've been using the script for some time in which case you may not be running the latest version on a modified site in which case email me your latest search.php and I'll add the filter code for you. To add filters for any custom fields, e.g. "colour" simply copy the code relating to brandFilter to add support for colourFilter.
With that in place an "advanced" search form can be created with drop-downs as required for merchant/category/brand and any custom fields added to the site. Assuming you've added "colour" as a field to your site, a basic search form with drop-down for colour would be as follows:
<div class='searchform'>
<form name='search' action='<?php print $config_baseHREF ?>search.php'>
<input type='text' name='q' id='q' size='35' value='<?php print (isset($q)?$q:""); ?>' />
<?php
$sql1 = "SELECT DISTINCT(colour) FROM `".$config_databaseTablePrefix."products` WHERE colour <> ''";
if (database_querySelect($sql1,$rows1))
{
print "<label for='colourFilter'>Colour:</label> ";
print "<select style='width:150px;' id='mf' name='colourFilter'>";
print "<option value=''>All</option>";
foreach($rows1 as $row)
{
$selected = ($_GET["colourFilter"]==$row["colour"]?"selected='selected'":"");
print "<option value='".htmlentities($row["colour"],ENT_QUOTES,$config_charset)."' ".$selected.">".$row["colour"]."</option>";
}
print "</select>";
}
?>
<input type='submit' value='<?php print translate("Search"); ?>' />
</form>
</div>
Cheers,
David.
--
PriceTapestry.com