运用循环实现PHP分类列表
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.phprm.com/frame/php1003893.html
转载随意,但请附上文章地址:-)