problem in creating a php tree menu
- by Mac Taylor
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