You are here:  » Generate a Merchant List for sidbar

Support Forum



Generate a Merchant List for sidbar

Submitted by TWDesigns on Wed, 2008-07-30 20:05 in

Does anyone know the code or if it's possible to generate a merchant list for use on the side of a site. Right now I'm manually copying name and URLs from the merchant page into a vertical side box. I would also like to be able to tell it to only show X number in case the list gets too big.

Thanks,
Tommy

Submitted by support on Thu, 2008-07-31 08:11

Hi Tommy,

That's straight forward as it will be a quick query; try something like this:

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

If you want to limit it to, say, 20 merchants, just add "LIMIT 20" to the end of the SQL, for example:

  $sql = "SELECT DISTINCT(merchant) as merchant FROM `".$config_databaseTablePrefix."products` ORDER BY merchant LIMIT 20";

Cheers,
David.

Submitted by TWDesigns on Thu, 2008-07-31 17:55

Hey David,

Thanks! It gave a blank screen at first but after removing
merchant:" from $href = $config_baseHREF."search.php?q="merchant:".urlencode($row["merchant"]).":";
it works fine.

Thanks,
Tommy