This paper illustrates the method of Smarty to realize multilevel classification. Share to everyone for your reference. The specific analysis is as follows:
Here a simple introduction to the use of PHP smarty multilevel classification Read and loop method, single cycle is very simple, but the multi-level will be more complex, let's look at the following, interested friends can look at:
Copy Code code 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 '] is the category id,parent_id is the sub-category owning ID
$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:
Copy Code code as follows:
<ul>
{foreach Name=cat from= $class item=cat}
<li><strong>{$cat. name}</strong>[{$cat .id}]</li>
<ul style= "padding-left:20px;" >
{foreach Name=subcat from= $subclass item=subcat}
{if $subcat. parent_id== $cat. ID}
<li>{$subcat. name}[{$subcat .parent_id}]</li>
{/if}
{/foreach}
</ul>
{/foreach}
</ul>
The results of the operation are shown in the following illustration:
I hope this article will help you with your PHP program design.