You are here:  » random brands

Support Forum



random brands

Submitted by rolli1 on Wed, 2012-01-25 09:56 in

Hi David,

I want to show 10 random Brands on my header page. I tried a lot with that random products code, but could not manage it. How can I manage that in the coding of header.php?

Thanks and regards

Roland

Submitted by support on Wed, 2012-01-25 10:02

Hi Roland,

The following code will generate links to 10 random brands:

<?php
  $sql 
"SELECT DISTINCT(brand) FROM `".$config_databaseTablePrefix."products` WHERE brand <> '' ORDER BY RAND() LIMIT 10";
  
database_querySelect($sql,$rows);
  print 
"<p>";
  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 
" <a href='".$href."'>".$row["brand"]."</a> ";
  }
  print 
"</p>";
?>

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by rolli1 on Wed, 2012-01-25 10:34

Perfect as always.
Thanks a lot.

Roland