一下为Smarty递归的调用方法,为什么我改不成普通的(去掉Smarty)?请高手指点department_list.php 文件<?php
require_once("config.php");
require_once("libs/Smarty.class.php");
$sm = new Smarty();
$sm -> assign("copyright",$config["copyright"]);
$sql="select 
a.departmentID,
a.departmentName,
a.departmentExplan,
a.parentID,
b.groupName 
from pdcs_department as a inner join pdcs_group as b On a.groupID=b.groupID
 order by a.departmentID desc
";
$result=mysql_query($sql) or die("could not connect" . mysql_error());
$abc="<table border=1 width=100%>";
$abc.="<tr>";
$abc.="<td>部门名称</td>";
$abc.="<td>部门介绍</td>";
$abc.="<td>所属角色</td>";
$abc.="<td>上级部门</td>";
$abc.="</tr>";
while($rs=mysql_fetch_array($result)){ 
$abc.="<tr>";
$abc.="<td>".$rs["departmentName"]."</td>";
$abc.="<td>".$rs["departmentExplan"]."</td>";
$abc.="<td>".$rs["groupName"]."</td>";
$abc.="<td>".$rs["parentID"]."</td>";
$abc.="</tr>";
}
$abc.="</table>";
$sm->assign("bodyarea",$abc);
$sm->display("default.html");
?>
department.php 文件<?php
require_once("config.php");
require_once("libs/Smarty.class.php");
$id=$_GET["id"];
$sm = new Smarty();
$sm -> assign("copyright",$config["copyright"]);
department_list();
function department_list($parent=0){
global $abc;
if (strlen($parent)==0){
$parent=0;
}else{
if (!is_numeric($parent)){
exit("<br>在输出部门列表过程中,出现一个致命性错误!因为父级编号不是有效的数字!");
}
if ($parent==0) {
}
}
$sql="select departmentID,departmentName,levelID from pdcs_department where parentID=$parent order by departmentID desc";
$result=mysql_query($sql) or die ("<br>$sql<br>".mysql_error());
while($rs=mysql_fetch_array($result)){
switch ($rs["levelID"] % 4){
case 1:
$color="#AAAAAA";
break;
case 2:
$color="#DADADA";
break;
case 3:
$color="#f0f0f0";
break;
case 0:
$color="#EEEEEE";
break;
}
$divWidth=$rs["levelID"] * 20;
$divWidth.="px";
$abc.="<div style=\"background-color:$color;padding:1px;text-align:left;margin:1px 0px 1px $divWidth;\">\n";
$abc.="<div style=\"float:right;width:100px\">";
$abc.="<a href=department_add.php?id=".$rs["departmentID"]."&levelID=".$rs["levelID"]."&Name=".$rs["departmentName"].">添加</a>";
$abc.="<a href=department_edit.php?id=".$rs["departmentID"].">修改</a>";
$abc.="<a href=department_delete.php?id=".$rs["departmentID"].">删除</a>";
$abc.="</div>\n";
$abc.=$rs["departmentName"];
$abc.="</div>\n";
department_list($rs["departmentID"]);
}
}
$sm->assign("bodyarea",$abc);
$sm->display("default.html");
?>