problem in creating a php tree menu
Posted
by Mac Taylor
on Stack Overflow
See other posts from Stack Overflow
or by Mac Taylor
Published on 2010-05-18T09:32:13Z
Indexed on
2010/05/18
9:40 UTC
Read the original article
Hit count: 228
hi mates
im writing a tree menu for my categories in php
and i wonder how can i code it correctly !
this is my table in database "
|----topicid------topicname--------parent |
|---- 1 ------ News -------- 0 |
|---- 2 ------ sport -------- 1 |
|---- 3 ------ games -------- 1 |
|---- 4 ------ PES -------- 3 |
so now for showing it like a tree i did try but not worked :
$result = mysql_query("SELECT * FROM Topics ORDER BY topicid");
while ($row = mysql_fetchrow($result)) {
$id = intval($row['topicid']);
$title = filter($row['topicname'], "nohtml");
$parent = $row['parent'] ;
if ($parent==0) {
$menu_item .= "<li><span class='folder'><a title = \"$alt\" href=\"modules.php?name=News&new_topic=$id\">$title</a></span></li>";
}else {
$result = mysql_query("SELECT * FROM ".$prefix."_Topics where parent='$id' ORDER BY topicid");
while ($row = mysql_fetchrow($result)) {
$id = intval($row['topicid']);
$title = filter($row['topicname'], "nohtml");
$parent = $row['parent'] ;
$menu_item .= " <ul><li><span class='file'><a title = \"$alt\" href=\"modules.php?name=News&new_topic=$id\">$title</a></span></li></ul>";
}
}
i dont know how to solve this
© Stack Overflow or respective owner