html代碼...用到兩個foreach 迴圈
- < div class="modContent">
- < %foreach from=$sort item=s%>
- < div class="categories">
- < acronym class="icon">< /acronym>
- < a href="category.php?sort_id=
< %$s.sort_id%>">
- < strong>< %$s.sort_name%>< /strong>
- < /a>< br />
- < %foreach from=$s.zi item=z%>
- < a href="category.php?sort_id=
< %$z.sort_id%>"
- title="< %$z.sort_name%>">
- < %$z.sort_name%>
- < /a>
- < %/foreach%>
- < /div>
- < %/foreach%>
- < /div>
PHP分類列表之PHP代碼 簡單的說就是利用foreach 迴圈一個數組然後在這個數組裡插入一個索引 索引對的直就是每次查詢的所有子分類
- //商品分類
- $sql="SELECT * FROM `hcl_sort`
WHERE `parent_id`=0 ORDER BY
`sort_id` DESC";
- $sort=$db->getAll($sql);
- foreach ($sort as $key=>$val){
- $sort_id=$sort[$key]['sort_id'];
- $sql="SELECT * FROM `hcl_sort`
WHERE `parent_id`={$sort_id}";
- $zi=$db->getAll($sql);
- $sort[$key]['zi']=$zi;
- }
- $tpl->assign('sort',$sort);
以上代碼就是PHP分類列表的具體解決方案。
http://www.bkjia.com/PHPjc/446076.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446076.htmlTechArticlehtml代碼...用到兩個foreach 迴圈 div class = modContent %foreach from =$sort item = s % div class = categories acronym class = icon /acronym a href = category.php?sort_id= %...