You are here:  » Show only Top 30 Brands

Support Forum



Show only Top 30 Brands

Submitted by atman on Sun, 2009-03-22 16:30 in

hi david.

Is it possible to show only the top 30 brands on sidebar?

This is a good mod to automatically populate the sidebar with the top 30 brands with the most number of products.

thanks.

Submitted by support on Mon, 2009-03-23 12:08

Hi atman,

The SQL to perform this is quite computationally heavy so may not be suited to being used to display a real time list of the top 30 brands - but in the first instance have a go with the following code inserted into your sidebar:

<?php
  
print "<h4>Top 30 Brands</h4>";
  
$sql "SELECT DISTINCT(brand) as brand, COUNT(brand) as count FROM `".$config_databaseTablePrefix."products` GROUP BY brand ORDER BY count DESC LIMIT 30";
  if (
database_querySelect($sql,$rows))
  {
    print 
"<ul>";
    foreach(
$rows as $row)
    {
      if (
$config_useRewrite)
      {
        
$href $config_baseHREF."brand/".tapestry_hyphenate($row["brand"])."/";
      }
      else
      {
        
$href $config_baseHREF."search.php?q=brand:".urlencode($row["brand"]).":";
      }
      print 
"<li><a href='".$href."'>".$row["brand"]."</a></li>";
    }
    print 
"</ul>";
  }
?>

Cheers,
David.