PHP头条
热点:

php无限级分类(带数据库)(1/2)


这是一款利用递归写的php无限级分类代码,是一款树型的无限级分类实例,一的无限都是利用递归来实现的,也有更高级的写法,二叉树来实现无限分类了。

php教程无限级分类(带数据库教程)
/*
这是一款利用递归写的php无限级分类代码,是一款树型的无限级分类实例,一的无限都是利用递归来实现的,也有更高级的写法,二叉树来实现无限分类了。
*/
?>

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<head>
<style type="text/css教程">
<!--
.menu { color:#000000; font-size: 12px; cursor: hand;}
</style>
<script type="text/网页特效">
function showmenu(menuid)
 {
 if(menuid.style.display=="none")
 {
 menuid.style.display="";
 }
 else
 {
 menuid.style.display="none";
 }
 }
</script>
<title>电视树状目录</title>
</head>
<body>
<?php
 $globals["id"] =1;
 $jibie=1;
 $sql="select * from tvmenu where bid=0";
 $result=mysql教程_query($sql,$conn);
 
 if(mysql_num_rows($result)>0)
 treemenu($conn,$result,$jibie,$id);
 
 function treemenu($conn,$result,$jibie)  //进入函数循环
 {
 $numrows=mysql_num_rows($result);
 echo "<table cellpadding='0' cellspacing='0' border='0'>";
 for($rows=0;$rows<$numrows;$rows++)
 {
 $menu=mysql_fetch_array($result);
 $sql="select * from tvmenu where bid=$menu[id]";
 $result_sub=mysql_query($sql,$conn);
 echo "<tr>";
  //如果该菜单项目有子菜单,则添加javascript onclick语句
  if(mysql_num_rows($result_sub)>0)
  {
  echo "<td width='20'><img src='+.gif' border='0'></td>";
  echo "<td class='menu' onclick='javascript:showmenu(menu".$globals["id"].");'>";
  }
  else
  {
  echo "<td width='20'><img src='-.gif' border='0'></td>";
  echo "<td class='menu'>";
  }
  if($menu[url]!="")
  echo "<a href='$menu[url]'>$menu[name]</a> ";
  else
  echo "<a href='#'>$menu[name]</a>   <a href='?b={$menu[id]}&tpye=add'> 添加</a>  <a href='?b={$menu[id]}&tpye=edit'> 编辑</a>  <a href='?b={$menu[id]}&action=del'> 删除</a>";
  echo "</td> </tr>";
  if(mysql_num_rows($result_sub)>0)
  {
  echo "<tr id=menu".$globals["id"]++." style='display:none'>";
  echo "<td width='20'> </td>";
  echo "<td>";
  //将级数加1
  $jibie++;
  treemenu($conn,$result_sub,$jibie);
  $jibie--;
  echo "</td></tr>";
  }
  //显示下一菜单
  }
  echo "</table>";
}
?>
<br />
<br />
<?php if ($tpye=="add") { ?>
<table width="551" border="0" cellpadding="0" cellspacing="1" bgcolor="#cccccc">
<form action="" method="post" name="form1">
  <tr>
    <td height="28" colspan="2" align="center" bgcolor="#ffffff">添加栏目</td>
  </tr>
  <tr>
    <td width="246" height="28" align="right" bgcolor="#ffffff">栏目名称:</td>
    <td width="302" height="28" bgcolor="#ffffff"><input name="name" type="text" id="name" /></td>
  </tr>
  <tr>
    <td height="28" align="right" bgcolor="#ffffff">所属分类:</td>
    <td height="28" bgcolor="#ffffff"><select name="bid">
<?php
   
 $sql="select * from tvmenu";
 $que=mysql_query($sql,$conn);
    while($rs=mysql_fetch_array($que)){
  if ($rs['id']==$b) {
     $selected="selected="selected"";
     }else{
     $selected="";
     }
 ?>
 
      <option value="<?php echo $rs["id"]; ?>" <?php echo $selected;?>><?php echo $rs["name"]; ?></option>
  <?php }?>
    </select>
    </td>
  </tr>
  <tr>
    <td height="28" colspan="2" align="center" bgcolor="#ffffff"><input type="submit" name="submit" value="提 交" /></td>
  </tr>
  </form>
</table>
<?php }?>

1 2

www.phpzy.comtrue/php/25638.htmlTechArticlephp无限级分类(带数据库)(1/2) 这是一款利用递归写的php无限级分类代码,是一款树型的无限级分类实例,一的无限都是利用递归来实现的,也有更高级的写法,二叉树来实现无限分类了...

相关文章

    暂无相关文章

PHP之友评论

今天推荐