html code... uses two foreach loops
PHP分类列表之PHP代码 简单的说就是利用foreach 循环一个数组然后在这个数组里插入一个索引 索引对的直就是每次查询的所有子分类
<ol class="dp-xml"> <li class="alt"><span><span>//商品分类 </span></span></li> <li> <span>$</span><span class="attribute">sql</span><span>=</span><span class="attribute-value">"SELECT * FROM `hcl_sort` <br>WHERE `parent_id`=0 ORDER BY <br>`sort_id` DESC"</span><span>; </span> </li> <li class="alt"> <span>$</span><span class="attribute">sort</span><span>=$db-</span><span class="tag">></span><span>getAll($sql); </span> </li> <li> <span>foreach ($sort as $</span><span class="attribute">key</span><span>=</span><span class="tag">></span><span>$val){ </span> </li> <li class="alt"> <span>$</span><span class="attribute">sort_id</span><span>=$sort[$key]['sort_id']; </span> </li> <li> <span>$</span><span class="attribute">sql</span><span>=</span><span class="attribute-value">"SELECT * FROM `hcl_sort`<br> WHERE `parent_id`={$sort_id}"</span><span>; </span> </li> <li class="alt"> <span>$</span><span class="attribute">zi</span><span>=$db-</span><span class="tag">></span><span>getAll($sql); </span> </li> <li><span>$sort[$key]['zi']=$zi; </span></li> <li class="alt"><span>} </span></li> <li> <span>$tpl-</span><span class="tag">></span><span>assign('sort',$sort); </span> </li> </ol>
以上代码就是PHP分类列表的具体解决方法。