PHP classification list using loops _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Use loops to implement the PHP classification list. Html code... two foreach loops are used: divclassmodContent % foreachfrom $ sortitems % divclasscategoriesacronymclassiconacronymahrefcategory. php? Sort_id %

Html code... two foreach loops are used

  1. < PClass = "modContent">
  2. <% Foreach from = $ sort item = s %>
  3. < PClass = "categories">
  4. < AcronymClass = "icon"> </Acronym>
  5. < AHref = "category. php? Sort_id =
    <% $ S. sort_id %>">
  6. < Strong> <% $ S. sort_name %> </Strong>
  7. </> < Br />
  8. <% Foreach from = $ s. zi item = z %>
  9. < AHref = "category. php? Sort_id =
    <% $ Z. sort_id %>"
  10. Title = "<% $ z. sort_name %>">
  11. <% $ Z. sort_name %>
  12. </>
  13. <%/Foreach %>
  14. </P>
  15. <%/Foreach %>
  16. </P>

PHP code for the PHP classification list is simply to use foreach to loop through an array and insert an index to this array. The result is that all subcategories are queried each time.

 
 
  1. // Product category
  2. $ SQL = "SELECT * FROM 'hcl _ sort'
    WHERE 'parent _ id' = 0 ORDER
    '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 solution to the PHP classification list.


Loop p class = modContent % foreach from = $ sort item = s % p class = categories acronym class = icon/acronym a href = category. php? Sort_id = %...

Related Article

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.