hi fellow monks
i'm playing around with setting up a website with perl/mysql.
tables:
- t_element (there i put all my elements with title, body, etc.)
- t_father2child (there i put together the elements. (f2c_id, f2c_fatherid, f2c_childid, f2c_nodetype)
- t_nodetype (there i store the type of the node: navigation, page, promotion)
i'm stuck with the navigation.
i'd like to make it look like:
nav 1
nav 2
nav 2.1
nav 2.1.1
nav 2.2
nav 3
(the sublevels only show up if you click on the above level. in the above i clicked on 'nav 2.1'. i do not want to see the sublevels of nav 1 and nav 3.)
so normally this ain't a problem. but since i do want to be flexible with the numbers of levels i'd like to do it with a recursive function.
the code i got until now:
sub doNavigation {
my $root = $_[0];
my $select = "f2c_id,f2c_fatherid";
my $from = "t_father2child";
my $where = "f2c_id = $root";
my @fathers = doSelect($select,$from,$where);
my $fatherId = $fathers[0][1];
loop($root,$fatherId);
} # end sub
sub loop {
my $root = $_[0];
my $father = $_[1];
my $select = "f2c_id,f2c_fatherid,f2c_childid,element_titel";
my $from = "(t_father2child INNER JOIN t_element ON f2c_ChildId = el
+ement_id)";
my $where = "f2c_fatherid = $father AND f2c_NodeTypeId = 1";
my @nodes = doSelect($select,$from,$where);
foreach my $node (0..$#nodes) {
print "<br><a href=?node_id=$nodes[$node][0]> - $nodes[$node][1] -
+ $nodes[$node][2] - $nodes[$node][3]</a>";
if ($nodes[$node][0] == $root) {
my $select = "f2c_id,f2c_fatherid,f2c_childid,element_titel";
my $from = "(t_father2child INNER JOIN t_element ON f2c_ChildId
+= element_id)";
my $where = "f2c_fatherid = $nodes[$node][2] AND f2c_NodeTypeId
+= 1";
my @children = doSelect($select,$from,$where);
if (@children) {
loop($root,$children[0][1]);
} # end children-if
} # end node-if
} # end node-foreach
}
it kinda works, but only shows me the selected level and the level below. i guess i could work with a dynamic-growing @ or something but i'm really stuck right now. any help from someone?
thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.