The data table structure for level Two classification is as follows:
Copy CodeThe code is as follows:
The PHP code is as follows
/**
@ article category with two levels of classification
@ param int $rootnum--Number of first class categories
@ param int $childnum--Level two class number
@ return value Array
@ Date 2011.2.24
*/
function Temp_articletreecate ($rootnum, $childnum) {
if (!isnumber ($rootnum)) {
$rootnum = 10;
}
if (!isnumber ($childnum)) {
$childnum = 10;
}
$category = Array ();
$parent _sql = "Select Cateid,catename from". Table_prefix. " Articlecate WHERE parentid=0 and Depth=0 and flag=1 ORDER by orders ASC ";
if (Intval ($rootnum) >0) {
$parent _sql.= "LIMIT $rootnum";
}
$parent _cate = $GLOBALS [' db ']->getall ($parent _sql);
foreach ($parent _cate as $parent _key = $parent _value) {
Subclass Array named Childcategory custom name according to the situation
$category [] = Array (' cateid ' = = $parent _value[' Cateid '), ' catename ' = = $parent _value[' catename '], ' Childcategory ' =>array ());
Read sub-class
$child _sql = "Select Cateid,catename from". Table_prefix. " Articlecate WHERE parentid= ". $parent _value[' Cateid ']." and flag=1 ORDER by orders ASC ";
if (Intval ($childnum) >0) {
$child _sql.= "LIMIT $childnum";
}
$child _cate = $GLOBALS [' db ']->getall ($child _sql);
foreach ($child _cate as $child _key = $child _value) {
$category [Count ($category) -1][' childcategory ' [] = Array (' Cateid ' = $child _value[' Cateid '], ' catename ' =>$ child_value[' Catename ');
}
}
return $category;
}
PHP page Call classification, such as index.php
$goodscatetree = Array ();
$goodscatetree = Temp_goodstreecate (4,0); Call classification function (with two levels of classification) 4--indicates that the first class category shows only 4, 0--represents an unlimited number of two classes
$tpl >assign ("Goodscatetree", $goodscatetree); Executing the Smarty engine
$tpl->display-> (INDEX.TPL); Output Smarty Template page
TPL template page output classifications, such as INDEX.TPL pages
{section name=p loop= $goodscatetree}
First-Class classification: {$goodscatetree [P].catename}
{section name=c loop= $goodscatetree [P].childcategory}
Level Two classification: {$goodscatetree [P].childcategory[c].catename}
{/section}
{/section}
http://www.bkjia.com/PHPjc/323429.html www.bkjia.com true http://www.bkjia.com/PHPjc/323429.html techarticle The data table structure of level Two classification is as follows: Copy code code as follows: PHP code is as follows/** @ article category with two levels category @ param int $rootnum--First class number @ param int $childnu ...