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@xxxxxxxxxx>
To: <php-general@xxxxxxxxxxxxx>; "php-db" <php-db@xxxxxxxxxxxxx>
Sent: Wednesday, October 20, 2004 4:47 AM
Subject: 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
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php