PDA

View Full Version : A hard one (PHP-related)


Nezzar
June 8th, 2002, 12:39
As you might already know I'm coding a message board (forget this vBulletin :p).
The problem is I want to give the user the ability to create subforums (like the beta-forum in the epsxe-forum here) but I dunno how. This would be no great deal if there could be only one suboforums but the user should be able to add as much subforums to another subforum as he wants.
I tried several ways with while-loops and this kind but nothing really worked.
I need this to know to create quick-nav-bar like the one you have on the bottom of every page here.
The forums table has this structure:

forumid tinyint(4) NOT NULL auto_increment,--simply the forums id
name varchar(200) NOT NULL default ''
description varchar(200) default NULL,
lastpost int(10) default NULL,
lastposter int(5) unsigned default NULL,
parent int(4) unsigned default '0',--the id of the forum that's the parent of the current forum
catid tinyint(4) NOT NULL default '0',--only needed if the forum isn't a subforum
path varchar(20) default '0',--from a mature try, this would've been the path "to the top", containing all the forums that are parents of the current forum

SnakeBite
June 9th, 2002, 19:29
Uh... don't ask me (You didn't either... that's good) I haven't used PHP at all...

ammoQ
June 15th, 2002, 13:31
what you need is recursion: (the following is only an example, not necessarily correct in terms of syntax etc.) Note that showforum calls itself to show the subforums of the current forum.

function showforum( $id , $level) {
echo "this is forum ", $id, " on level ", $level;

$subforums = odbc_exec($connection, "select forumid from forums where parent = $id");

while ( odbc_fetch_row($subforums) ) {
$subid = odbc_result($subforums, 1);

showforum($subid, $level+1);
}
odbc_free_result($subforums);
}

Nezzar
June 15th, 2002, 14:53
Thanks, I got a similar answer on another forum, but I didn't understand it. Thanks for helping out, d00d.