Home > Backend Development > PHP Tutorial > Using loops to implement PHP classification lists_PHP tutorial

Using loops to implement PHP classification lists_PHP tutorial

WBOY
Release: 2016-07-15 13:33:03
Original
780 people have browsed it

html code... uses two foreach loops

  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>    
  13. < %/foreach%> 
  14. < /div>   
  15. < %/foreach%> 
  16. < /div> 

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>
Copy after login

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


www.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= %...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template