I would like to diplay comments on my site like this:
<li>Parent
<ul>
<li>child one</li>
<li>child two
<ul>
<li>grandchild</li>
<li>other grandchild</li>
</ul>
</li>
</ul>
<li>Another parent with no children</li>
<li>
I have read the following article, however it doesn’t use <li>. So is there a way to display comments like I’ve done before with an array like so? Thanks.
$comments = array(
array('id'=>1, 'parent_id'=>NULL, 'text'=>'Parent'),
array('id'=>2, 'parent_id'=>1, 'text'=>'Child'),
array('id'=>3, 'parent_id'=>2, 'text'=>'Child Third level'),
array('id'=>4, 'parent_id'=>NULL, 'text'=>'Second Parent'),
array('id'=>5, 'parent_id'=>4, 'text'=>'Second Child')
);
I asssume your comment table has id, parent_id, comment, … and my suggestion goes like this;
Select you comments like;
And next step is array operations.You can see the following code below and try working demo here;
For demo please see here