Any ideas on how can I generate a nested list without the need to recreate a lot of select statements?
I'm currently using this code
<ol>
<?php
$getparents=mysql_query("select id,subject from list");
while($parent=mysql_fetch_assoc($getparents)){
?>
<li><?php echo $parent["id"];?></li>
<?php
$childsparent=$parent["id"];
$getchild=mysql_query("select id,subject from list where parent_id='".$childsparent."'");
if (!mysql_num_rows($getchild){
echo '</ol>';
}
else
{
echo '<ol>';
while ($child=mysql_fetch_assoc($getchild)){
echo '<li>'.$child["subject"].'</li>';
}
$childsparent=$child["id"];
}
?>
</ol>
Is there a way to stop the while from getting all results and check a result first if it has child nests before it moves forward?
The result should be something like
1.
2.
2.1
2.1.1
2.2
3