当前位置:编程学习 > php >>

php 无限分类(非递归)

<? 
/**
 * 无限分类
 * 2011/8/24
 * kcj
 * */ 
include "../conn/conn.php"; 
$flpid=$_POST['flpid']; 
$fltitle=$_POST['title']; 
$fldes=$_POST['des']; 
if(isset($_POST['action'])!=''&&$_POST['action']="add"){               // 无限分类(非递归),用路径来判断分类归属(flid=flpid)  
        $sql2="select flpath from fenlei where flid=".$flpid; 
        $rst2=mysql_query($sql2); 
        $row=mysql_fetch_array($rst2,MYSQL_ASSOC); 
        $flpath=$row['flpath']; 
    $sql="insert into fenlei (flpid,fltitle,fldes,flpath) value('".$flpid."','".$fltitle."','".$fldes."','".($flpath.'-'.$flpid)."')"; 
    mysql_query($sql); 
     

 
?> 
 
 
 
<html> 
    <head> 
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 
        <title>无标题文档</title> 
        <meta name="Author" content="kcj" /> 
        <meta name="Keywords" content="php,lampbrother" /> 
        <link rel="stylesheet" type="text/css" href="style/lampcms.css"> 
        <script src="javascript/common.js"></script> 
        <script type="text/javascript"> 
           function vaFl(addfl){ 
             if(addfl.title.value==''){ 
                alert("栏目名称不能为空!"); 
                addfl.title.focus(); 
                return false; 
             } 
             if(addfl.des.value==''){ 
                alert("栏目描述不能为空!"); 
                addfl.des.focus(); 
                return false; 
             } 
           } 
         
        </script> 
         
    </head> 
    <body> 
        <div id="main"> 
              后台管理->添加分类 
            <form  method="post" action="" name="addfl" onsubmit="return vaFl(this)"> 
            <div class="msg-box"> 
                <ul class="viewmess"> 
                    <li class="light-row"> 
                        <span class="col_width">上级栏目</span> 
                          <select name="flpid"> 
                     <option value="0">请选择分类</option> 
                           <?php 
    $sql="SELECT*FROM fenlei where flpid=0";                   //这一块只是在下拉列表中,显示易做图分类(可以显示更多,循环出来就ok了!)  
    $rs=mysql_query($sql); 
    while ($row=mysql_fetch_array($rs)) {  var_dump($row); 
      echo "<option value=\"$row[flid]\">$row[fltitle]</option>"; 
 
 
      $sql="select*from  fenlei where flpid=$row[flid]"; 
        $rs_son=mysql_query($sql); 
        while($row_son=mysql_fetch_array($rs_son)){ 
        echo "<option value=\"$row_son[flid]\">   $row_son[fltitle]</option>"; 
             
            $sql="select*from  fenlei where flpid=$row_son[flid]"; 
            $rs_son_one=mysql_query($sql); 
            while($row_son_one=mysql_fetch_array($rs_son_one)){ 
            echo "<option value=\"$row_son_one[flid]\">      $row_son_one[fltitle]</option>"; 
                
      }    
      } 
 
    } 
    ?> 
                          </select> 
                    </li> 
                  
补充:Web开发 , php ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,