您的位置:首页 > 编程语言 > PHP开发

php实现无限级分类

2016-05-10 09:36 736 查看
如果自己写一个系统,经常会用到栏目管理

栏目分类多等级多就需要实现无限级分类了,代码如下

一、下拉菜单中的使用

/*  无限级分类
*
*	逻辑递推获取类型
*	hid 上级栏目id
*	step 下级栏目前缀
*	tid seleted选项id
*/

function LogicGetTypeList($datatable='lanmu_class',$hid=0,$step='',$tid=-1)
{

static $TypeList='';
$query = "SELECT * FROM `$datatable` WHERE heid=$hid ORDER BY px ASC";
$arrs=mysql_query($query);
while($row=@mysql_fetch_assoc($arrs)){
echo $step;
$TypeList .= ("<option value='".$row['id']."' ");
$TypeList .= ($tid == $row['id']? 'selected' : '');
$TypeList .= (" >".$step.$row['class']."</option>\r\n");  //分类名称
LogicGetTypeList($datatable,$row['id'],$step.'--',$tid);
}
return $TypeList;
}


二、栏目管理
代码大概如下,需要根据具体情况进行修改

<?php
treeList("",0);
function treeList($tag,$classid){
$result=mysql_query("select * from lanmu_class where heid='".$classid."' order by px asc");
while($row=mysql_fetch_array($result)){

/*栏目功能*/
$sqlG=@mysql_fetch_assoc(mysql_query("select * from ht_gn where id='".$row['gongn']."'"));
?>
<tr class="blue" onmouseover="c=this.style.backgroundColor;this.style.backgroundColor='#daebf8'" onmouseout="this.style.backgroundColor=c" onclick="ClickEvent('')">
<td width="5" align="center" class=""><input type="checkbox" name="dell[]" value="<?php echo $row['id']?>"></td>
<td class=""><?php echo $tag.$row['class'];?></td>
<td class=""><?php echo $sqlG['gn_title'];?></td>
<td align="center" class=""><?php echo $row['template'];?> </td>
<td align="center" class=""><input type="text" value="<?php echo $row["px"]?>" size="3" onblur="modify(<?php echo $row['id'];?>,this.value)" /> </td>
<td class="">
【<a href="lanmu_add.php?id=<?php echo $row['id'];?>">编辑</a>】  【<a href="#" onclick="if(confirm('您确定要删除吗?')){location.href='lanmu_exe.php?del=<?php echo $row['id']?>'}">删除</a>】
  【<a href="../car/car_pic.php?s_id=<?php echo $row['id'];?>">图片集</a>】
</td>
</tr>
<?php treeList($tag."─┴─",$row['id']);?>
<?php
}
}
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: