You are here:  » Homepage merchant, category and brand drop downs

Support Forum



Homepage merchant, category and brand drop downs

Submitted by support on Sat, 2008-03-29 10:52 in

Hi all,

Just posting these snippets for someone i'm helping out by email, but may be useful for others...

Merchant Drop Down

<?php
  $sql 
"SELECT DISTINCT(merchant) as merchant FROM `".$config_databaseTablePrefix."products` ORDER BY merchant";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<form id='merchantDropdown' method='GET' action='".$config_baseHREF."search.php' />";
    print 
"<select name='q' onchange='JavaScript:document.getElementById(\"merchantDropdown\").submit();'>";
    print 
"<option>Merchant</option>";
    foreach(
$rows as $row)
    {
      
$value "merchant:".$row["merchant"].":";
      print 
"<option value='".$value."'>".$row["merchant"]."</option>";
    }
    print 
"</select>";
    print 
"<noscript><input type='submit' value='Go' /></noscript>";
    print 
"</form>";
  }
?>

Category Drop Down

<?php
  $sql 
"SELECT DISTINCT(category) as category FROM `".$config_databaseTablePrefix."products` ORDER BY category";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<form id='categoryDropdown' method='GET' action='".$config_baseHREF."search.php' />";
print 
"<select name='q' onchange='JavaScript:document.getElementById(\"categoryDropdown\").submit();'>";
    print 
"<option>Category</option>";
    foreach(
$rows as $row)
    {
      
$value "category:".$row["category"].":";
      print 
"<option value='".$value."'>".$row["category"]."</option>";
    }
    print 
"</select>";
    print 
"<noscript><input type='submit' value='Go' /></noscript>";
    print 
"</form>";
  }
?>

Brand Drop Down

<?php
  $sql 
"SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` ORDER BY brand";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<form id='brandDropdown' method='GET' action='".$config_baseHREF."search.php' />";
    print 
"<option>Brand</option>";
print 
"<select name='q' onchange='JavaScript:document.getElementById(\"brandDropdown\").submit();'>";
    foreach(
$rows as $row)
    {
      
$value "brand:".$row["brand"].":";
      print 
"<option value='".$value."'>".$row["brand"]."</option>";
    }
    print 
"</select>";
    print 
"<noscript><input type='submit' value='Go' /></noscript>";
    print 
"</form>";
  }
?>

Please note - this is only really suitable for niche sites - it is not recommend for large sites with hundreds of categories!