This article mainly introduces how to implement multi-level classification by smarty. It involves loop reading techniques and is very useful. For more information, see
This article mainly introduces how to implement multi-level classification by smarty. It involves loop reading techniques and is very useful. For more information, see
This article describes how smarty implements multi-level classification. Share it with you for your reference. The specific analysis is as follows:
Here is a brief introduction to the use of php smarty multi-level classification reading and loop methods. Single Loop is very simple, but multi-level reading is complicated. Let's take a look at it. Interested friends can look at it:
The Code is as follows:
<? Php
$ Result = mysql_query ("SELECT id, description, parent_id, name, sort_order FROM article_categoey WHERE parent_id = 0 order by id ");
While ($ row = mysql_fetch_array ($ result )){
$ Class [] = $ row;
// $ Row ['id'] indicates the category id and parent_id indicates the id of the subcategory.
$ Result_sub = mysql_query ("SELECT id, description, parent_id, name, sort_order FROM article_categoey WHERE parent_id = '". $ row ['id']. "'order by id ");
While ($ row_sub = mysql_fetch_array ($ result_sub )){
$ Subclass [] = $ row_sub;
}
$ Smarty-> assign ("subclass", $ subclass );
}
$ Smarty-> assign ("class", $ class );
$ Smarty-> display('articles.html ');
?>
The HTML code is as follows:
The Code is as follows:
{Foreach name = cat from = $ class item = cat}
- {$ Cat. name}[{$ Cat. id}]
{Foreach name = subcat from = $ subclass item = subcat}
{If $ subcat. parent_id = $ cat. id}
- {$ Subcat. name} [{$ subcat. parent_id}]
{/If}
{/Foreach}
{/Foreach}
Shows the running result:
I hope this article will help you with PHP programming.