首页 > php框架 > 运用循环实现PHP分类列表

运用循环实现PHP分类列表

html代码...用到两个foreach 循环

  1. < div class="modContent"> 
  2. < %foreach from=$sort item=s%> 
  3. < div class="categories"> 
  4. < acronym class="icon">< /acronym>
  5. < a href="category.php?sort_id=
    < %$s.sort_id%>"
    >
  6. < strong>< %$s.sort_name%>< /strong>
  7. < /a>< br /> 
  8. < %foreach from=$s.zi item=z%> 
  9. < a href="category.php?sort_id=
    < %$z.sort_id%>"
     
  10. title="< %$z.sort_name%>">
  11. < %$z.sort_name%>
  12. < /a>&nbsp;&nbsp;  
  13. < %/foreach%> 
  14. < /div>   
  15. < %/foreach%> 
  16. < /div> 

PHP分类列表之PHP代码 简单的说就是利用foreach 循环一个数组然后在这个数组里插入一个索引 索引对的直就是每次查询的所有子分类

  1. //商品分类  
  2. $sql="SELECT * FROM `hcl_sort` 
    WHERE `parent_id`=0 ORDER BY 
    `sort_id` DESC"
    ;  
  3. $sort=$db->getAll($sql);  
  4. foreach ($sort as $key=>$val){  
  5. $sort_id=$sort[$key][sort_id];  
  6. $sql="SELECT * FROM `hcl_sort`
     WHERE `parent_id`={$sort_id}"
    ;  
  7. $zi=$db->getAll($sql);  
  8. $sort[$key][zi]=$zi;  
  9. }  
  10. $tpl->assign(sort,$sort); 

以上代码就是PHP分类列表的具体解决方法。


本文地址:http://www.phprm.com/frame/php1003893.html

转载随意,但请附上文章地址:-)

标签:none

发表留言