smarty模版引擎的二级分类php代码详解

来源:爱站网时间:2021-04-27编辑:网友分享
其实只要是程序员就应该知道smarty模版引擎输出二级分类代码,最关键的点就在于它是靠二维数组进行控制输出的,以下小编将为你分享二级分类的数据表结构以及相关的PHP代码详情。

二级分类的数据表结构如下:


PHP代码如下

复制代码 代码如下:

/**
@ 文章分类 含二级分类
@ param int $rootnum -- 一级分类数量
@ param int $childnum -- 二级分类数量
@ 返回值 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){
//子类数组名为 childcategory 根据情况自定义名称
$category[] = array('cateid'=>$parent_value['cateid'],'catename'=>$parent_value['catename'],'childcategory'=>array());

//读取子类
$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页面调用分类,如index.php

 

复制代码 代码如下:

 


$goodscatetree = array();
$goodscatetree = temp_goodstreecate(4,0); //调用分类函数(含二级分类)4--表示一级分类只显示4个,0--表示二级分类不限数量
$tpl>assign("goodscatetree",$goodscatetree); //执行smarty引擎
$tpl->display->(index.tpl); //输出smarty模版页面


TPL模版页面输出分类,如index.tpl页面

 

 

以上就是小编为大家分享的二级分类的数据表结构、PHP页面调用分类以及TPL模版页面输出分类的页面php代码详解,如果有需要的话,可以直接进行拷贝。

上一篇:laravel上传图片报错:413 Request Entity Too Large的详细解决方法

下一篇:Prototype (原型模式)代码到底是什么样的

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载