PDA

Click to See Complete Forum and Search --> : [RESOLVED] Forum - Breadcrumb - Parent Forums


dclamp
Jul 5th, 2008, 11:41 PM
Ok i am making a forum, and it allows unlimited sub-forums. How my db is set up, it is has a parentforumID for the parent forum of that forum. (duh).

If there is no parent forum then it is equal to 0. So i need to do a breadcrumb for this, and i tried using a while loop, but it doesnt seem to work.

What am i doing wrong?


if ($forums->forumExists($_GET['forumid'])) {
$catID = $forums->getCategoryID($_GET['forumid']);
$catname = $forums->getCategoryName($catID);
$forumname = $forums->getForumName($_GET['forumid']);
$breadcrumb = "&gt; <a href='?action=home#cat_{$catID}'>{$catname}</a> ";
$forumID = mysql_real_escape_string($_GET['forumid']);
$sql1 = "SELECT `parentforumID` FROM `".$db_prefix."forums` WHERE forumID='{$forumID}' LIMIT 1";
$query1 = mysql_query($sql1);
$res1 = mysql_fetch_array($query1);
if ($res1['parentforumID'] == 0) {
$breadcrumb .= "&gt; {$forumname}";
} else {
$parentID = $res['parentforumID'];
while ($parentID!=0) {
$sql = "SELECT `parentforumID` FROM `".$db_prefix."forums` WHERE forumID='{$parentID}' LIMIT 1";
$query = mysql_query($sql) or die(mysql_error());
$res = mysql_fetch_array($query);
$name = $forums->getForumName($parentID);
$breadcrumb .= "&gt; <a href='?action=viewforum&forumid={$parentID}'>{$name}</a> ";
$parentID = $res['parentforumID'];
}
}
} else {
$breadcrumb = "&gt; Error";
}

visualAd
Jul 6th, 2008, 05:29 PM
You need to use a recursive function to produce the breadcrumbs.

dclamp
Jul 6th, 2008, 05:35 PM
can you give me an example?

visualAd
Jul 6th, 2008, 06:06 PM
It looks nice to use recursion. But the code above looks ok; so what is the problem?

function breadcrumbs($forumId)
{
$breadCrumbs = '';

if($parentForum != 0) {
return $breadCrumbs;
} else {
/* add new link here */
$breadCrumbs .= breadCrumbs($parentForum);
}
}

dclamp
Jul 6th, 2008, 06:32 PM
my code isnt doing anything. It isnt echoing a breadcrumb or any errors.

visualAd
Jul 7th, 2008, 12:48 AM
Use a few echos to find out exactly how far it is getting.

dclamp
Jul 17th, 2008, 10:20 PM
ok i tried to do the breadcrumb, and looking at your code, it confuses me...

dclamp
Jul 17th, 2008, 10:48 PM
ahhh! i figured it out. My code was all correct. I just misnamed a variable :)

visualAd
Jul 19th, 2008, 09:17 AM
ahhh! i figured it out. My code was all correct. I just misnamed a variable :)
That's why you should always ensure you have error reporting set to E_ALL.

dclamp
Jul 19th, 2008, 03:09 PM
:blush: