You are here:  » Search

Support Forum



Search

Submitted by JasonG on Thu, 2013-05-02 14:23 in

Hi David

Do you ahve any code already written to have a search box, then a drop down so searches can be made in a specific category?

Thanks in advance
Stuart

Submitted by support on Thu, 2013-05-02 14:47

Hi Stuart,

First check your search.php and see if you have the categoryFilter code - it's included in the latest distribution and in numerous mods so I suspect you may already have the code in place - look around line 16 for the following code:

  $categoryFilter = ($_GET["categoryFilter"]?$_GET["categoryFilter"]:"");

If that's in place, a drop-down can simply be added to the search form. To do this, edit html/searchform.php and add the following code on the line immediately before the submit / Search button:

<?php
$sql 
"SELECT DISTINCT(category) FROM `".$config_databaseTablePrefix."products` WHERE category <> '' ORDER BY category";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<select name='categoryFilter'>";
    print 
"<option value=''>All Categories</option>";
    foreach(
$rows as $row)
    {
      
$selected = ($_GET["categoryFilter"]==$row["category"]?"selected='selected'":"");
      print 
"<option value='".htmlspecialchars($row["cateogory"])."' ".$selected.">".$row["category"]."</option>";
    }
    print 
"</select>";
  }
?>

If you don't have $categoryFilter handling code in your search.php, email me your current version and I'll merge that for you...

Cheers,
David.
--
PriceTapestry.com

Submitted by JasonG on Thu, 2013-05-02 16:31

Thanks, will take a look