Re: Reverse (or backward?) Infinity Loop

From: Date: Wed, 20 Oct 2004 14:30:35 +0000
Subject: Re: Reverse (or backward?) Infinity Loop
References: 1 2 3  Groups: php.db 
Request: Send a blank email to php-db+get-36927@lists.php.net to get a copy of this message
this is some code i've written once that gets all supercategories from a mysql db... Take it as it is... It prints out a html-string of links like this: Category : sub_cat1 : sub_cat2 : sub_cat3. Maybe you can figure it out... it takes the current id (in your example catId13) as a parameter and goes up to the root... function catPathRec($id, $show_lnk = false, $rtn_val="") { global $link_id; $katname = strtoupper(mysql_result(mysql_query("SELECT kat_namn AS kat FROM text_kat WHERE id = ".$id, $link_id), "kat")); $hid = mysql_result(mysql_query("SELECT h_id AS hkat FROM text_kat WHERE id = ".$id, $link_id), "hkat"); if ($rtn_val == "") { if ($show_lnk) { return ($hid == 0) ? ("<a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>") : (catPathRec($hid, $show_lnk, " : <a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>")); } else { return ($hid == 0) ? ($katname) : (catPathRec($hid, $show_lnk, " : ".$katname)); } } else if ($hid != 0) { return catPathRec($hid, $show_lnk, " : <a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>".$rtn_val); } return "<a href='text.php?action=kat&kat_id=".$id."' style='font-weight:normal;' onfocus='this.blur()'>".$katname."</a>".$rtn_val."\n"; } ----- Original Message ----- From: "Bruno B B Magalhães" <brunobbm@rio.com.br> To: <php-general@lists.php.net>; "php-db" <php-db@lists.php.net> Sent: Wednesday, October 20, 2004 4:47 AM Subject: [PHP-DB] Reverse (or backward?) Infinity Loop Hi guys, I have a normal categories table: catId catParentId catName catStatus But I want when a user enters on: http://hostname/site/products/catId1/catId7/catId13/../../contentId.html A listing should apear like that: • Category 1
     • Category 7
          • Category 13
• Category 2 • Category 3 • Category 4 • Category 5 A reverse (or backward) loop! We need to get the last category and then follow the ParentId until the 0 ParentId. Have anybody made this before (I hope so)? Many Thanks, Bruno B B Magalhaes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.db (#36927) next »