程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php 無限分類(非遞歸)

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> 
                    <li class="dark-row"> 
                        <span class="col_width">欄目名稱<span class="red_font">*</span></span> 
                        <input type="text" class="text-box" name="title" maxlength="30" size="20" > 
                    </li> 
                    <li class="light-row"> 
                        <span class="col_width" style="margin-top:30px">欄目描述</span> 
                        <textarea class="text-box" name="des" cols="30" rows="5"></textarea> 
                    </li> 
                     
 
                    <li class="light-row"> 
                        <span class="col_width">   </span> 
                        <input type="hidden" name="action" value="add"> 
                        <input type="submit" class="button" name="mod" value="添加分類">   
                        <input type="reset" class="button" value="重 置"> 
                    </li> 
                </ul>  
            </div> 
                    </form>    
        </div> 
    </body> 
</html> 

摘自 chaojie2009的專欄

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved