Hack: Function to display category tree: (Top Cat -> Sub

In this board you can talk about general questions about phpMyFAQ

Moderator: Thorsten

Post Reply
bass000
Posts: 5
Joined: Mon Jun 28, 2004 2:11 pm

Hack: Function to display category tree: (Top Cat -> Sub

Post by bass000 »

Here is a function which can be useful.

I use it in the Top 5 new added row.

Please feel free to reuse it and tell me if you do.

Bests.

Code: Select all

/*
 * Function which returns the current tree of the $num category:
 * example: Top Cat -> Sub Cat -> SubSubCat 
 */
function get_category_tree($num)
{
global $db;

 $cattable=NULL;
 $seperator=" -> ";
 $strreturn="";
 $i=0;
 
 while($i<strlen($num))
 {
 	$i=$i+3;
 	$cattable[]=substr($num,0,$i);
 }
  
 foreach($cattable as $value){
 	$query = "SELECT ".$sqltblpre."faqrubrik.titel FROM ".$sqltblpre."faqrubrik WHERE rubrik = '".$value."'";
    $result = $db->query($query);
    
    if ($db->num_rows($result) == 1) {
        $row = $db->fetch_object($result);
        $strreturn.=makeShorterText($row->titel,8).$seperator;
    }
  }
  //Last separator is deleted
$strreturn=substr($strreturn,0 ,strlen($strreturn)-strlen($seperator));
return $strreturn;
}
Thorsten
Posts: 15560
Joined: Tue Sep 25, 2001 11:14 am
Location: #phpmyfaq
Contact:

Post by Thorsten »

Nice hack!

bye
Thorsten
phpMyFAQ Maintainer and Lead Developer
amazon.de Wishlist
Post Reply