Using loops to implement PHP classification list _php Tutorial

Source: Internet
Author: User

HTML code ... Use of 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 >

The PHP Code of the PHP classification list is simply to use the Foreach Loop an array and then insert an indexed index pair in this array straight is all sub-categories of each query

 
 
  1. Product Categories
  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);

The above code is the specific way to solve the PHP classification list.


http://www.bkjia.com/PHPjc/446076.html www.bkjia.com true http://www.bkjia.com/PHPjc/446076.html techarticle HTML code ... Use two foreach loop div class = Modcontent%foreach from = $sort item = s% div class = categories Acronym class = Icon/acronym a href = category.php?sort_id=% ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.