p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   PHP Databases (http://p2p.wrox.com/forumdisplay.php?f=97)
-   -   Problems with displaying sub-cats... (http://p2p.wrox.com/showthread.php?t=28345)

enchen April 20th, 2005 05:23 AM

Problems with displaying sub-cats...
 
Hi, I run a small News-script using mySQL/PHP and use the following function to call the category table and create a you-are-here link menu...

The category table consists of 4 fields
xid (cat id auto inc)
catalogname
description
parentid

function caturher($xid)
   {
      global $T_Catalog;
      $sql = "select catalogname,parentid from TableCatalog where xid='$xid'";
      $result = $this->select($sql);
      $cat = $result[0]["catalogname"];
      $parent = $result[0]["parentid"];
      if ($parent != "0") {
      $sql = "select xid,catalogname from $T_Catalog where xid='$parent'";
      $result2 = $this->select($sql);
      $txid = $result2[0]["xid"];
      $tcat = $result2[0]["catalogname"];
      $urher = "\n<a class=\"you_menu\" href=\"?choice=section&amp;xid=$txid\">$tcat</a> &raquo; ";
      }
      $urher .= $cat;
      return $urher;
   }

It works fine for 2 levels, e.g. home > news > archive, but if I add a subcat "test" under "archive" it displays home > archive > test instead of home > news > archive > test which off course would be the desired path to show...

I've tried various things like foreach and a while loop but I can`t seam to get this function to do what I want it to, namely to be able to print the path for "unlimited" number of sub categories.

Any help is VERY MUCH appreciated :(


All times are GMT -4. The time now is 02:44 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.