I am playing around with a code example i found here about 'tree menu' and wanted to make this question.
function tree($id)
{
$query = "SELECT `name`,`id` from `table` WHERE `id_parrent` = '$id'";
$result = mysql_query($query);
if(mysql_num_rows($result) != 0)
{
echo "<ul>";
while($row = mysql_fetch_array($result))
{
echo "<li>",$row[name],"</li>";
tree($row[id]);
}
echo "</ul>";
}
}
what if i want to display items in a way like this:
<ul>
<li>item 1</li>
<li>item 2</li>
<li style="padding-left:10px;">item 3-has parent 2</li>
<li style="padding-left:20px;">item 4-has parent 3</li>
<li style="padding-left:10px;">item 5-has parent 2</li>
<li>item 6</li>
</ul>
My main problem is to find the level somehow so that i could multiply level*padding and create my list. Any suggestions would be appreciated.