You are here:  » Subcategory links list on specific pages

Support Forum



Subcategory links list on specific pages

Submitted by Kelly and Stuart on Sat, 2008-06-21 12:49 in

Hi David
I have a furniture site and I have a static page for each room in the house which uses searchcode.php to get the products
i.e. bathroom.php is:

<h1>Bathroom</h1>
<?php
  $_GET["q"] = "category:Bathroom:";
  $_GET["sort"] = "priceDesc";
    require("searchcode.php");
  require("html/footer.php");
?>

In my imports I have used brands as a subcategory, so category would be bathroom and brands would be bathroom cabinets.

Is it possible to to bring up a list of links just under the header, using the brand field something along the lines of

$sql = "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE category LIKE bathroom% ORDER BY brand";

and have the results displayed as a link to a search query?
if yes, where do I put it?
Many thanks in advance
Kelly

Submitted by support on Sat, 2008-06-21 13:11

Hi Kelly,

Try something like this which can go anywhere provided that $_GET["q"] is set...

<?php
  $tempParts 
explode(":",$_GET["q"]);
  if (
$tempParts[0]=="category")
  {
    
$sql "SELECT DISTINCT(brand) as brand FROM `".$config_databaseTablePrefix."products` WHERE category='".database_safe($tempParts[1])."' ORDER BY brand";
    if (
database_querySelect($sql,$rows))
    {
      print 
"<ul>";
      foreach(
$rows as $row)
      {
        
$href $config_baseHREF."search.php?q=brand:".urlencode($row["brand"]);
        print 
"<li><a href='".$href."'>".$row["brand"]."</a></li>";
      }
      print 
"</ul>";
    }
  }
?>

Cheers,
David.

Submitted by Kelly and Stuart on Sat, 2008-06-21 16:15

Your a star - works a treat, just what I was looking for.
Many thanks
Kelly