You are here:  » Multiple search choices drop down boxes

Support Forum



Multiple search choices drop down boxes

Submitted by babrees on Sun, 2012-05-20 10:33 in

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

Submitted by support on Mon, 2012-05-21 07:54

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>&nbsp;";
    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

Submitted by babrees on Tue, 2012-05-22 15:03

Hi David

search.php sent :)

>>Assuming you've added "colour" as a field to your site

Submitted by babrees on Wed, 2012-05-23 07:04

I'd also like to search by price range?

Cheers
---------
Jill

Submitted by support on Wed, 2012-05-23 07:58

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

Submitted by enjoymarcus on Tue, 2012-08-14 16:27

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.

Submitted by support on Wed, 2012-08-15 08:45

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)."&amp;";
  }

...and finally at line 357 add:

  if ($platformFilter)
  {
    $sort .= "&amp;platformFilter=".urlencode($platformFilter);
  }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by enjoymarcus on Wed, 2012-08-15 14:30

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.

Submitted by support on Wed, 2012-08-15 15:02

Hi Marc,

That should work fine - could you email me your modified search.php plus 2 example URLs after applying the filter - one working and one not working example and I'll check it out...

Cheers,
David.
--
PriceTapestry.com