You are here:  » Setting up filters

Support Forum



Setting up filters

Submitted by Andrewc on Thu, 2009-07-16 07:16 in

Hi David

I have implemented the filter hack that I found you posted on some other post..

$sql = "SELECT DISTINCT brand FROM `".$config_databaseTablePrefix."products` WHERE category = '".database_safe($parts[1])."' LIMIT 10";
  if (database_querySelect($sql,$rows))
  {
  print_r($rows);
echo "<div class='headleft'>Filter by Brand </div>";
echo "<ul>";
    foreach($rows as $row)
    {
      $brandHREF = $config_baseHREF."search.php?q=".urlencode($q)."&amp;brandFilter=".urlencode($row["brand"]);
      echo "<li><a href='".$brandHREF."'>".$row["brand"]."</a></li>";
    }
echo "</ul>";
  }

The issue is it is still displaying the Filter box even though the query returns 0 rows.
Printing out the Rows array shows: Array ( [0] => Array ( [brand] => ) )
So brand is still returning with a blank item in therefore passing the if() statement..

Any help?

Submitted by support on Thu, 2009-07-16 08:51

Hi Andrew,

Adding a WHERE clause to exclude the empty brand should do the trick...

$sql = "SELECT DISTINCT brand FROM `".$config_databaseTablePrefix."products` WHERE category = '".database_safe($parts[1])."' AND brand <> '' LIMIT 10";

Cheers,
David.

Submitted by Andrewc on Thu, 2009-07-16 09:02

yea that solved it..

Heard somewhere that it is faster to us != than <>