How do I generate tree(?) list using control structure like 'while'?
This is what I like to do:
- List 1
- Sublist 1
- Sublist 2
- Sublist 3
- List 2
- Sublist 1
- Sublist 2
Datas come from database (MySQL).
If I have code just like below:
$query = mysql_query("SELECT * FROM music");
I can generate the first list using the standard code below:
while ($res = mysql_fetch_array($query)) {
echo "<li>$res[0]</li>";
}
But I can't think what I have to code with the sub-list.
I can't just do this:
while ($res = mysql_fetch_array($query)) {
echo "<li>$res[0]"
."<ul>"
."<li>$res[1]"
.</ul></li>";
}
because it'll have result like the list below:
- List 1
- Sublist 1
- List 1
- Sublist 2
- List 1
- Sublist 3
- List 2
- Sublist 1
- List 2
- Sublist 2
which is I don't intent to.
Would someone help me?