我正在尝试制作一个菜单树。我的数据库中的表格如下所示:
| id | int(10) unsigned | NO | PRI | NULL | |
| title | varchar(255) | NO | | NULL | |
| parentId | int(10) unsigned | YES | | NULL | |
| level | tinyint(3) unsigned | NO | | NULL | |
| sortOrder | int(10) unsigned | YES | | NULL | |
我的数据库连接正常。我做了一个这样的循环:
$test = connexion_DB($db);
$strSQL = "SELECT id, parentId, title, level FROM my_table ORDER BY title ASC";
$sql = requete_SQL($strSQL);
$categories = array();
while($row = mysql_fetch_array($sql)) {
$categories[] = array(
'parentId' => $row['parentId'],
'level' => $row['level'],
'title' => $row['title']
);
}
...但我不知道如何做树菜单?像这样:
<ul>
<li>Canins
<ul>
<li>Chiens</li>
<li>Loups</li>
</ul>
</li>
<li>Félins
<ul>
<li>Grands Félins
<ul>
<li>Lions</li>
<li>Panthères</li>
<li>Tigres</li>
</ul>
</li>
<li>Petits Félins</li>
</ul>
</li>
<li>Poissons
<ul>
<li>Requins</li>
<li>Saumons</li>
</ul>
</li>
</ul>
有人有想法吗?