溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

打造PHP的無限分級類的完整代碼及注釋是什么

發(fā)布時間:2021-10-18 16:32:53 來源:億速云 閱讀:113 作者:柒染 欄目:編程語言

這篇文章將為大家詳細講解有關(guān)打造PHP的無限分級類的完整代碼及注釋是什么,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。

下面提供一個PHP的無限分級類代碼,想要實現(xiàn)無限分級類的朋友們可以試試。Bug已經(jīng)檢查修正過,直接復制代碼就能使用(尖括號需要替換一下)。

1、數(shù)據(jù)庫ProductShow中有b_mtype表,建表語句如下:

CREATE TABLE `b_mtype` (    `typeid` int(4) NOT NULL default '0',    `typename` varchar(50) NOT NULL default '',    `parentid` int(4) NOT NULL default '0',    `parentstr` varchar(200) NOT NULL default '',    `depth` int(4) NOT NULL default '0',    `rootid` int(4) NOT NULL default '0',    `child` varchar(200) NOT NULL default '',    `orders` varchar(200) NOT NULL default '',    PRIMARY KEY  (`typeid`)  ) TYPE=MyISAM;

2、ProductClass.php代碼:(直接復制即可)

< html>  < head>  < meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  < title>WHB_PHP無限級分類< /title>  < style type="text/css">  < !--  .STYLE1 {color: #FF0000}  body,td,th {   font-family: 宋體;   font-size: 12px;  }  .STYLE2 {   color: #FFFFFF;   font-size: 14px;   font-weight: bold;  }  -->  < /style>  < /head>   < body>  < ?php  ini_set("error_reporting","E_ALL & ~E_NOTICE");//忽略所有警告信息   require_once("conn.php");//嵌入連接文件      @$ToDo=$_GET["ToDo"];      switch($ToDo)      {              case "add":      echo add();      break;           case "edit":       echo edit();      break;        case "saveadd":       echo saveadd();      break;           case "saveedit":      echo saveedit();      break;           case "del":      echo del();      break;              default:  ?>   < table width="90%"   border="0" align="center" cellpadding="0" cellspacing="0" class="tblborder">  < tr>       < td valign="top">< table width="100%"   border="0" cellspacing="1" cellpadding="3">         < tr>             < td width="55%" height="20" align="center" bgcolor="#698FC7">< span class="tblhead">< b>< span class="STYLE2">商品類別設(shè)置< /span> < a href="?ToDo=add">添加一個新類別< /a>< /b>< /span>< /td>                      < /tr>       < /table>         < table width="100%" bgcolor="#cccccc" cellspacing="1" cellpadding="3">           < tr bgcolor="#F9F9F9">             < td width="6%" height="21">ID< /td>             < td width="49%">類別名稱< /td>             < td width="14%">排序< /td>             < td width="31%">操作< /td>           < /tr>     < ?php              $query=mysql_query("select * from b_mtype order by rootid,orders");     while($arr=mysql_fetch_array($query))     {          ?>           < tr>             < td   bgcolor="#FFFFFF">< ?php echo $arr["typeid"];?>< /td>             < td   bgcolor="#FFFFFF">< ?php if ($arr["depth"]>0) {                        for($i=1;$i< =$arr["depth"];$i++){ echo "&nbsp;";}       }?>          < ? if($arr["child"]>0) { echo "+";}else {echo "-";}?>          < ? if($arr["parentid"]==0) { echo "< b>";}?>         < ? echo $arr["typename"];?>         < ? if ($arr["child"]>0) {?>(< ? echo $arr["child"];?>)< ? }?>< /td>             < td bgcolor="#FFFFFF">< ?php echo $arr["orders"];?>< /td>             < td bgcolor="#FFFFFF">< a href="?ToDo=add&editid=< ?php echo $arr["typeid"];?>">< U>添加子類< /U>< /a>        | < a href="?ToDo=edit&editid=< ?php echo $arr["typeid"]?>">< U>編輯類別< /U>< /a>               |   < ? if($arr["child"]==0){?>< a href="?ToDo=del&editid=< ? echo $arr["typeid"];?>" onClick="{if(confirm('刪除類別時,該類別下的所有產(chǎn)品將一并被刪除,確定刪除嗎?')){return true;}return false;}">< U>刪除類別< /U>< /a>< ?}else{?>< a href="#" onClick="{if(confirm('該類別含有下屬類別,必須先刪除其下屬類別方能刪除本類別!')){return true;}return false;}">< U>刪除類別< /U>< /a>< ?}?>&nbsp;< /td>           < /tr>     < ?php     }     ?>         < /table>       < /td>     < /tr>  < /table>   < ?php       break;      }      ?>    < ?php   ///增加類別  function add(){      @$editid=$_REQUEST["editid"];  ?>      < form name="form1" method="post" action="?ToDo=saveadd">           < table width="90%"   align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">             < tr bgcolor="#CCCCCC">               < td colspan="2" align="center" bgcolor="#698FC7">< span class="STYLE2">創(chuàng)建新的類別< /span>< /td>             < /tr>                          < tr>               < td width="25%" bgcolor="#FFFFFF">類別名稱:< /td>               < td width="75%" bgcolor="#FFFFFF">< input name="typename" type="text" id="typename">< /td>             < /tr>            < tr>               < td width="25%" height=30 bgcolor="#FFFFFF">< U>所屬類別< /U>< /td>              < td width="75%" bgcolor="#FFFFFF">                < select name=btype>               < option value="0">做為主類別< /option>               < ?        $query=mysql_query("select * from b_mtype order by rootid,orders");          while($arr=mysql_fetch_array($query)){ ?>               < option value="< ? echo $arr["typeid"]?>" < ?php if($editid == $arr['typeid']){ echo " selected"; }?>>               < ? if($arr["depth"]>0) {                 for($i=1;$i< =$arr["depth"];$i++)        {          echo "-";            }                         }?>                < ? echo $arr["typename"]?>< /option>               < ?             }                  ?>               < /select>               < /td>             < /tr>             < tr>               < td bgcolor="#FFFFFF">&nbsp;< /td>               < td bgcolor="#FFFFFF">< input type="submit" name="Submit" value="保存">                 < label>                 < input type="button" name="cancel" id="cancel" value="返回" onclick="history.go(-1);" />               < /label>< /td>             < /tr>           < /table>  < /form>  < ? }?>   < ?php    /////保存增加的類別  function saveadd(){   $query=mysql_query("select typeid from b_mtype order by typeid desc limit 1");  while($arr=mysql_fetch_array($query)){  if (!$arr["typeid"]){        $postnum=1;      }else{        $postnum=$arr["typeid"]+1;      }     }  if(!$postnum) $postnum=1;   $ntid   =$postnum;  $tn     =$_REQUEST["typename"];  $btype =$_REQUEST["btype"];    //echo $btype;   if ($ntid=="" or $tn=="")  {  echo "< script language='javascript'>";  echo "alert('參數(shù)有誤,請重新填寫.!');";  echo "location.href='?';";  echo "< /script>";  die();  }   if ($btype!=0){          $result=mysql_query("select rootid,typeid,depth,orders,parentstr from b_mtype where typeid='$btype'");      $aa=mysql_fetch_array($result);      $rootid=$aa['rootid'];      //echo "aaaaaaaaaaa";      $parentid=$aa['typeid'];      $depth=$aa['depth'];      $orders=$aa['orders'];      $parentstr=$aa['parentstr'];      //echo $rootid;       if(($aa["depth"]+1)>20){   die("本分類限制最多只能有20級分類"); }   }   if($ntid == $btype)  {  echo "< script language='javascript'>";  echo "alert('您所指定的typeid值重復!');";  echo "location.href='?';";  echo "< /script>";  die();  }   if($btype!=0){      $depth=$depth+1;     $rootid=$rootid;     $orders =$ntid;     $parentid =$btype;     //$child = $child;     if ($parentstr=="0"){        $parentstr=$btype;     }else{        $parentstr=$parentstr.",".$btype;     }   }else{     $depth=0;     $rootid=$ntid;     $orders=1;     $parentid=0;     $child=0;     $parentstr=0;  }   //插入類別  $query=mysql_query("insert into b_mtype values('$ntid','$tn','$parentid','$parentstr','$depth','$rootid','','$orders')") ;  //用于調(diào)試 echo "insert into b_mtype values('$ntid','$tn','$parentid','$parentstr','$depth','$rootid','','$orders')";   if ($btype!=0)     {        if ($depth>0)        {           //當上級分類深度大于0的時候要更新其父類(或父類的父類)的版面數(shù)和相關(guān)排序           for ($i=1;$i< =$depth;$i++){              //更新其父類版面數(shù)              if ($parentid!=""){                 $query=mysql_query("update b_mtype set child=child+1 where typeid='$parentid'");              }              //得到其父類的父類的版面ID              $result=mysql_query("select parentid from b_mtype where typeid='$parentid'");              $par=mysql_fetch_array($result);                  if ($par['parentid']!=""){                $parentid=$par['parentid'];              }              //當循環(huán)次數(shù)大于1并且運行到最后一次循環(huán)的時候直接進行更新              if ($i==$depth && $parentid!=""){                $query=mysql_query("update b_mtype set child=child+1 where typeid='$parentid'");              }            }//for循環(huán)結(jié)束            //更新該版面排序以及大于本需要和同在本分類下的版面排序序號            $query=mysql_query("update b_mtype set orders=orders+1 where rootid='$rootid' and orders>'$orders'");            //$orders1=$orders+1;            //echo "orders1=".$orders1;            $query=mysql_query("update b_mtype set orders='$orders'+1 where typeid='$ntid'");                }else{  //對應(yīng)if ($depth>0),當上級分類深度為0的時候只要更新上級分類版面數(shù)和該版面排序序號即可            $query=mysql_query("update b_mtype set child=child+1 where typeid='$btype'");          $result=mysql_query("select max(orders) from b_mtype where typeid='$ntid'");          $ord=mysql_fetch_array($result);             $query=mysql_query("update b_mtype set orders='$ord[0]'+1 where typeid='$ntid'");          }        }     echo "< script language='javascript'>";  echo "alert('類別添加成功!');";  echo "location.href='?';";  echo "< /script>";  }  ?>   < ?PHP    ////修改設(shè)置  function edit(){     //global $db,$editid,$tn,$arr;   $editid=$_REQUEST["editid"];   $result=mysql_query("select * from b_mtype where typeid='$editid'");  $tn=mysql_fetch_array($result);  ?>       < form   name="form2" action ="?ToDo=saveedit" method="post">         < input type="hidden" name="editid" value="< ?php echo $editid;?>">  < table width="90%" border="0"   align=center cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">  < tr>   < th height=24 colspan=2 bgcolor="#698FC7" class="STYLE2">編輯類別:< ?PHP echo $tn["typename"];?>< /th>  < /tr>  < tr>   < td width="44%" height=30 bgcolor="#FFFFFF">類別名稱< /td>  < td width="56%" bgcolor="#FFFFFF">   < input type="text" name="typename" size="35"   value="< ?php echo $tn["typename"];?>">  < /td>  < /tr>   < tr>   < td width="44%" height=30 bgcolor="#FFFFFF">< p>所屬類別< /p>    < p>    < span class="STYLE1">特別提示:< /span>< br />      所屬類別不能指定當前類別(即自己)為父類別< BR>      所屬類別不能指定當前類別的子類別為父類別< /p>< /td>  < td width="56%" bgcolor="#FFFFFF">   < select name="class">  < option value="0">做為主類別< /option>  < ?   $query=mysql_query("select * from b_mtype order by rootid,orders");   while($arr=mysql_fetch_array($query))  { ?>  < option value="< ?php echo $arr[typeid]?>" < ?php if ($tn["parentid"] == $arr["typeid"]) { echo "selected"; } ?>>< ? if ($arr["depth"]>0) {?>  < ?for ($i=1;$i< =$arr["depth"];$i++){ echo "-";}?>  < ? } ?>< ?php echo $arr["typename"]?>< /option>  < ?  }  ?>  < /select>  < /td>  < /tr>   < tr>   < td width="44%" height=24 bgcolor="#FFFFFF">&nbsp;< /td>  < td width="56%" bgcolor="#FFFFFF">   < input type="submit" name="Submit" value="提交修改">  < /td>  < /tr>  < /table>  < /form>   < ?   }   ?>    < ?php   /////保存修改  function saveedit(){     //global $db,$aa,$bb,$cc,$dd,$ee,$ff,$gg,$ii,$jj,$kk,$ll,$mm,$nn,$qq,$rr;     $editid=$_REQUEST["editid"];     $btype=$_REQUEST["class"];     $tn=$_REQUEST["typename"];      if($editid == $btype ){   echo "< script language='javascript'>";      echo "alert('所屬類別不能指定當前類別(即自己)為父類別!');";      echo "location.href='?';";      echo "< /script>";      die();    }      $result=mysql_query("select * from b_mtype where typeid='$editid'");     $aa=mysql_fetch_array($result);     $newtypeid=$aa["typeid"];     $typename=$aa["typename"];     $parentid=$aa["parentid"];     $iparentid=$aa["parentid"];     $parentstr=$aa["parentstr"];     $depth = $aa["depth"];     $rootid = $aa["rootid"];     $child = $aa["child"];     $orders = $aa["orders"];      ////判斷所指定的類別是否其下屬類別     if ($parentid ==0){  if ($btype!= 0) {  $result=mysql_query("select rootid from b_mtype where typeid='$btype'");  $b=mysql_fetch_array($result);  if ($rootid == $bb['rootid']) {   echo "< script language='javascript'>";      echo "alert('所屬類別不能指定當前類別的子類別為父類別!');";      echo "location.href='?';";      echo "< /script>";      die();      }   }       }else{  $result=mysql_query("select typeid from b_mtype where parentstr like '%$parentstr%' and typeid='$btype'");  $cc=mysql_fetch_array($result);  if ($cc[0]){     echo "< script language='javascript'>";      echo "alert('所屬類別不能指定當前類別的子類別為父類別!');";      echo "location.href='?';";      echo "< /script>";      die();     }     }      if ($parentid ==0){  $parentid=$editid;  $iparentid=0;     }     mysql_query("update b_mtype set typename='$tn',parentid='$btype' where typeid='$editid'");      $result1=mysql_query("select max(rootid) from b_mtype");     $ss=mysql_fetch_array($result1);     $maxrootid=$ss["rootid"]+1;     if (!$maxrootid){ $maxrootid=1;}       //假如更改了所屬類別  //需要更新其原來所屬版面信息,包括深度、父級ID、版面數(shù)、排序、繼承版主等數(shù)據(jù)  //需要更新當前所屬版面信息  //繼承版主數(shù)據(jù)需要另寫函數(shù)進行更新--取消,在前臺可用typeid in parentstr來獲得   if ($parentid != $btype && !($iparentid==0 && $btype==0)) {      //如果原來不是一級分類改成一級分類      //echo "ggg";        if ($iparentid>0 && $btype==0)         {     //更新當前版面數(shù)據(jù)     mysql_query("update b_mtype set depth=0,orders=0,rootid='$editid',parentid=0,parentstr='0' where typeid='$newtypeid'");     $parentstr=$parentstr .",";     $result=mysql_query("select count(*) from b_mtype where parentstr like '%$parentstr%'");     $dd=mysql_fetch_array($result);     $postcount=$dd[0];      if (emptyempty($postcount))      {         $postcount=1;         }else{         $postcount=$postcount+1;         }     //更新其原來所屬類別版面數(shù)     mysql_query("update b_mtype set child=child-'$postcount' where typeid='$iparentid'");     //更新其原來所屬類別數(shù)據(jù),排序相當于剪枝而不需考慮     for ($i=1;$i< =$depth;$i++)      {      ////得到其父類的父類的版面ID      $result2=mysql_query("select parentid from b_mtype where typeid='$iparentid'");      $ee=mysql_fetch_array($result2);      if (!$ee[0]){       $iparentid=$ee[0];       mysql_query("update b_mtype set child=child-'$postcount' where typeid='$iparentid'");             }         } //for end         if ($child >0){     //m1     //更新其下屬類別數(shù)據(jù)     //有下屬類別,排序不需考慮,更新下屬類別深度和一級排序ID(rootid)數(shù)據(jù)     //更新當前版面數(shù)據(jù)            $i=0;       $query=mysql_query("select * from b_mtype where parentstr like '%$parentstr%'");       while($arr=mysql_fetch_array($query)){        $i++;       $mParentStr=strtr($arr['parentstr'],$parentstr," ");       mysql_query("update b_mtype set depth=depth-'$depth',rootid='$maxrootid',parentstr='$mParentStr' where typeid='$arr[typeid]");       }      }   //m1 end      }elseif ($iparentid > 0 && $btype >0) {              //將一個分類別移動到其他分類別下       //獲得所指定的類別的相關(guān)信息       $result=mysql_query("select * from b_mtype where typeid='$btype'");       $gg=mysql_fetch_array($result);       //得到其下屬版面數(shù)       $parentstr=$parentstr .",";       $iparentstr=$parentstr.$editid;       echo $iparentstr;       $result1=mysql_query("select count(*) from b_mtype where parentstr like '%$iparentstr%'");       $ii=mysql_fetch_array($result1);       $postcount=$ii[0];       if (emptyempty($postcount)){ $postcount=1; }        //在獲得移動過來的版面數(shù)后更新排序在指定類別之后的類別排序數(shù)據(jù)         $query=mysql_query("update b_mtype set orders=orders+'$postcount'+1 where rootid='$gg[rootid]' and orders>'$gg[orders]'");       //更新當前版面數(shù)據(jù)        If($gg[parentstr]=="0") {                 // $idepth=$gg[depth]+1;          // $iorders=$gg[orders]+1;            mysql_query("update b_mtype set depth='$gg[depth]'+1,orders='$gg[orders]'+1,rootid='$gg[rootid]',parentid='$btype',parentstr='$gg[typeid]' where typeid='$newtypeid'");        }Else{        $aparentstr=$gg['parentstr'].",".$gg['typeid'];           $idepth=$gg['depth']+1;           $iorders=$gg['orders']+1;           mysql_query("update b_mtype set depth='$idepth',orders='$iorders',rootid='$gg[rootid]',parentid='$btype',parentstr='$aparentstr' where typeid='$editid'");        }        $i=1;        //如果有則更新下屬版面數(shù)據(jù)        //深度為原有深度加上當前所屬類別的深度     $iparentstr=$parentstr.$newtypeid;          $query=mysql_query("select * from b_mtype where parentstr like '%$iparentstr%' order by orders");        while($arr=mysql_fetch_array($query)){    // m2         $i++;             If ($gg['parentstr']=="0") {              $iParentStr=$gg['typeid'].",".strtr($arr['parentstr'],$parentstr," ");          }Else{              $iParentStr=$gg["parentstr"] .",".$gg["typeid"] . "," . strtr($arr['parentstr'],$parentstr," ");          }              $query=mysql_query("update b_mtype set depth=depth+'$gg[depth]'-'$depth'+1,orders='$gg[orders]'+'$i',rootid='$gg[rootid]',parentstr='$iParentStr' where typeid='$arr[typeid]'");        }   ///m2 end         $parentid=$btype;        if ($rootid==$gg['rootid']) {   ///m3       //在同一分類下移動       //更新所指向的上級類別版面數(shù),i為本次移動過來的版面數(shù)       //更新其父類版面數(shù)         $query=mysql_query("update b_mtype set child=child+'$i' where (! parentid=0) and typeid='$parentid'");         for ($k=1;$k< =$gg['depth'];$k++){     //得到其父類的父類的版面ID       $result=mysql_query("select parentid from b_mtype where (! parentid=0) and typeid='$parentid'");       $vv=mysql_fetch_array($result);        if ($vv[0]){      $parentid=$vv[0];      //更新其父類的父類版面數(shù)      mysql_query("update b_mtype set child=child+'$i' where (! parentid=0) and   typeid='$parentid'");         }              } // for end        //更新其原父類版面數(shù)        mysql_query("update b_mtype set child=child-'$i' where (! parentid=0) and typeid='$iparentid'");        //更新其原來所屬類別數(shù)據(jù)         for ($k=1;$k< =$depth;$k++){       //得到其原父類的父類的版面ID       $result1=mysql_query("select parentid from b_mtype where (! parentid=0) and typeid='$iparentid'");       $zz=mysql_fetch_array($result1);       if ($zz[0]){      $iparentid=$zz[0];           //更新其原父類的父類版面數(shù)      mysql_query("update b_mtype set child=child-'$i' where (! parentid=0) and   typeid='$iparentid'");        }       }//for end               }else{   ////m3 end       //更新所指向的上級類別版面數(shù),i為本次移動過來的版面數(shù)       //更新其父類版面數(shù)      mysql_query("update b_mtype set child=child+'$i' where typeid='$parentid'");       for ($k=1;$k< =$gg["depth"];$k++){     //得到其父類的父類的版面ID     $result2=mysql_query("select parentid from b_mtype where typeid='$parentid'");     $yy=mysql_fetch_array($result2);     if ($yy[0]){      $parentid=$yy[0];      //更新其父類的父類版面數(shù)      mysql_query("update b_mtype set child=child+'$i' where typeid='$parentid'");      }            } //for end        //更新其原父類版面數(shù)        mysql_query("update b_mtype set child=child-'$i' where typeid='$iparentid'");        //更新其原來所屬類別數(shù)據(jù)        for ($k=1;$k< =$depth;$k++){     //得到其原父類的父類的版面ID     $query=mysql_query("select parentid from b_mtype where typeid='$iparentid'");     while($arr=mysql_fetch_array($query))      {           if ($arr[0]){            $iparentid=$arr[0];            //更新其原父類的父類版面數(shù)            mysql_query("update b_mtype set child=child-'$i' where typeid='$iparentid'");               }          }         } //for end       } ///m3 end        }else{  //如果原來是一級類別改成其他類別的下屬類別  //得到所指定的類別的相關(guān)信息  $result=mysql_query("select * from b_mtype where typeid='$btype'");  $gg=mysql_fetch_array($result);  echo $rootid;  $result1=mysql_query("select count(*) from b_mtype where rootid='$rootid'");  $qq=mysql_fetch_array($result1);  $postcount=$qq[0];  //更新所指向的上級類別版面數(shù),i為本次移動過來的版面數(shù)  $parentid=$btype;  //更新其父類版面數(shù)  mysql_query("update b_mtype set child=child+'$postcount' where typeid='$parentid'");   for ($k=1;$k< =$gg['depth'];$k++){     //得到其父類的父類的版面ID     $result2=mysql_query("select parentid from b_mtype where typeid='$parentid'");     $rr=mysql_fetch_array($result2);     if ($rr[0]){      $parentid=$rr[0];      //更新其父類的父類版面數(shù)      mysql_query("update b_mtype set child=child+'$postcount' where typeid='$parentid'");     }   } ///for end   //在獲得移動過來的版面數(shù)后更新排序在指定類別之后的類別排序數(shù)據(jù)  mysql_query("update b_mtype set orders=orders+'$postcount'+1 where rootid='$gg[rootid]' and orders>'$gg[orders]'");  $i=0;  $query=mysql_query("select * from b_mtype where rootid='$rootid' order by orders");  while($arr=mysql_fetch_array($query))  {      $i++;      if ($arr['parentid'] ==0)      {     if ($gg['parentstr'] =="0")      {             $parentstr=$gg['typeid'];         }else{            $parentstr=$gg['parentstr'] .",".$gg['typeid'];         }       mysql_query("update b_mtype set depth=depth+'$gg[depth]'+1,orders='$gg[orders]'+'$i',rootid='$gg[rootid]',parentstr='$parentstr',parentid='$btype' where typeid='$arr[typeid]'");           }else{     if ($gg['parentstr'] =="0"){           $parentstr=$gg['typeid'] ."," . $arr['parentstr'];         }else{           $parentstr=$gg['parentstr'] .",".$gg['typeid'] .",". $arr['parentstr'];         }        mysql_query("update b_mtype set depth=depth+'$gg[depth]'+1,orders='$gg[orders]'+'$i',rootid='$gg[rootid]',parentstr='$parentstr' where typeid='$arr[typeid]'");        }     }///while end  }//else end   }  echo "< script language='javascript'>";  echo "alert('類別修改成功!');";  echo "location.href='?';";  echo "< /script>";  }  ?>   < ?php   function   del(){   ////更新其上級版面類別數(shù),如果該類別含有下級類別則不允許刪除  $editid=$_REQUEST["editid"];  $result=mysql_query("select parentstr,child,depth from b_mtype where typeid='$editid'");  $aa=mysql_fetch_array($result);  if ($aa[0]!="") {  if ($aa[1]>0){   echo "< script language='javascript'>";      echo "alert('該類別含有下屬類別,必須先刪除其下屬類別方能刪除本類別!');";      echo "location.href='?';";      echo "< /script>";      die();   }  //如果有上級版面,則更新數(shù)據(jù)   if ($aa[2]>0){  $query=mysql_query("update b_mtype set child=child-1 where typeid in ($aa[0])");  }  $query=mysql_query("delete from b_mtype where typeid='$editid'");    }  echo "< script language='javascript'>";  echo "alert('類別刪除成功!');";  echo "location.href='?';";  echo "< /script>";  }  ?>  < /body>  < /html>

試試看這個無限分級類吧!

關(guān)于打造PHP的無限分級類的完整代碼及注釋是什么就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

php
AI