首頁 > 後端開發 > php教程 > 打造PHP的无限分级类(完整代码及注释)_PHP教程

打造PHP的无限分级类(完整代码及注释)_PHP教程

WBOY
發布: 2016-07-13 17:19:02
原創
880 人瀏覽過

下面提供一个PHP的无限分级类代码,想要实现无限分级类的朋友们可以试试。Bug已经检查修正过,直接复制代码就能使用尖括号需要替换一下)。

1、数据库ProductShow中有b_mtype表,建表语句如下:

<ol class="dp-sql">
<li class="alt"><span><span class="keyword">CREATE</span><span> </span><span class="keyword">TABLE</span><span> `b_mtype` (  </span></span></li>
<li class="">
<span>  `typeid` </span><span class="keyword">int</span><span>(4) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">'0'</span><span>,  </span>
</li>
<li class="alt">
<span>  `typename` </span><span class="keyword">varchar</span><span>(50) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">''</span><span>,  </span>
</li>
<li class="">
<span>  `parentid` </span><span class="keyword">int</span><span>(4) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">'0'</span><span>,  </span>
</li>
<li class="alt">
<span>  `parentstr` </span><span class="keyword">varchar</span><span>(200) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">''</span><span>,  </span>
</li>
<li class="">
<span>  `depth` </span><span class="keyword">int</span><span>(4) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">'0'</span><span>,  </span>
</li>
<li class="alt">
<span>  `rootid` </span><span class="keyword">int</span><span>(4) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">'0'</span><span>,  </span>
</li>
<li class="">
<span>  `child` </span><span class="keyword">varchar</span><span>(200) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">''</span><span>,  </span>
</li>
<li class="alt">
<span>  `orders` </span><span class="keyword">varchar</span><span>(200) </span><span class="op">NOT</span><span> </span><span class="op">NULL</span><span> </span><span class="keyword">default</span><span> </span><span class="string">''</span><span>,  </span>
</li>
<li class="">
<span>  </span><span class="keyword">PRIMARY</span><span> </span><span class="keyword">KEY</span><span>  (`typeid`)  </span>
</li>
<li class="alt"><span>) TYPE=MyISAM;  </span></li>
<li class=""><span> </span></li>
</ol>
登入後複製

2、ProductClass.php代码:直接复制即可)

<ol class="dp-c">
<li class="alt"><span><span>  </span></span></li>
<li class=""><span>  </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"Content-Type"</font></span><span> content=</span><span class="string"><font color="#0000ff">"text/html; charset=gb2312"</font></span><span> />  </span></span></li>
<li class=""><span>WHB_PHP无限级分类  </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"text/css"</font></span><span>>  </span></span></li>
<li class=""><span><li class="alt"><span>.STYLE1 {color: #FF0000}  </span></li>
<li class=""><span>body,td,th {  </span></li>
<li class="alt"><span> font-family: 宋体;  </span></li>
<li class=""><span> font-size: 12px;  </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>.STYLE2 {  </span></li>
<li class="alt"><span> color: #FFFFFF;  </span></li>
<li class=""><span> font-size: 14px;  </span></li>
<li class="alt"><span> font-weight: bold;  </span></li>
<li class=""><span>}  </span></li>
<li class="alt"><span>-->  </span></li>
<li class=""><span>  </span></li>
<li class="alt"><span>  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>  </span></li>
<li class=""><span><li class="alt">
<span></span><span class="func">ini_set</span><span>(</span><span class="string"><font color="#0000ff">"error_reporting"</font></span><span>,</span><span class="string"><font color="#0000ff">"E_ALL & ~E_NOTICE"</font></span><span>);</span><span class="comment"><font color="#008200">//忽略所有警告信息  </font></span><span> </span>
</li></span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">require_once</font></strong></span><span>(</span><span class="string"><font color="#0000ff">"conn.php"</font></span><span>);</span><span class="comment"><font color="#008200">//嵌入连接文件 </font></span><span> </span>
</li></span></li>
<li class="alt">
<span>    @</span><span class="vars"><font color="#dd0000">$ToDo</font></span><span>=</span><span class="vars"><font color="#dd0000">$_GET</font></span><span>[</span><span class="string"><font color="#0000ff">"ToDo"</font></span><span>];  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">switch</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$ToDo</font></span><span>)  </span>
</li>
<li class="alt"><span>    {          </span></li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">case</font></strong></span><span> </span><span class="string"><font color="#0000ff">"add"</font></span><span>:  </span>
</li>
<li class="alt">
<span>    </span><span class="func">echo</span><span> add();  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li>
<li class="alt"><span>     </span></li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">case</font></strong></span><span> </span><span class="string"><font color="#0000ff">"edit"</font></span><span>:  </span>
</li>
<li class="alt">
<span>     </span><span class="func">echo</span><span> edit();  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span>     </span><span class="keyword"><strong><font color="#006699">case</font></strong></span><span> </span><span class="string"><font color="#0000ff">"saveadd"</font></span><span>:  </span>
</li>
<li class="alt">
<span>     </span><span class="func">echo</span><span> saveadd();  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li>
<li class="alt"><span>     </span></li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">case</font></strong></span><span> </span><span class="string"><font color="#0000ff">"saveedit"</font></span><span>:  </span>
</li>
<li class="alt">
<span>    </span><span class="func">echo</span><span> saveedit();  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li>
<li class="alt"><span>     </span></li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">case</font></strong></span><span> </span><span class="string"><font color="#0000ff">"del"</font></span><span>:  </span>
</li>
<li class="alt">
<span>    </span><span class="func">echo</span><span> del();  </span>
</li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li>
<li class="alt"><span>        </span></li>
<li class="">
<span>    </span><span class="keyword"><strong><font color="#006699">default</font></strong></span><span>:  </span>
</li>
<li class="alt"><span>?>  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"90%"</font></span><span>   border=</span><span class="string"><font color="#0000ff">"0"</font></span><span> align=</span><span class="string"><font color="#0000ff">"center"</font></span><span> cellpadding=</span><span class="string"><font color="#0000ff">"0"</font></span><span> cellspacing=</span><span class="string"><font color="#0000ff">"0"</font></span><span> </span><span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"tblborder"</font></span><span>>  </span></span></li>
<li class=""><span>  </span></li>
<li class="alt"><span>     <span class="string"><font color="#0000ff">"top"</font></span><span>><span class="string"><font color="#0000ff">"100%"</font></span><span>   border=</span><span class="string"><font color="#0000ff">"0"</font></span><span> cellspacing=</span><span class="string"><font color="#0000ff">"1"</font></span><span> cellpadding=</span><span class="string"><font color="#0000ff">"3"</font></span><span>>  </span></span><li class=""><span>         </span></li>
<li class="alt"><span>           <span class="string"><font color="#0000ff">"55%"</font></span><span> height=</span><span class="string"><font color="#0000ff">"20"</font></span><span> align=</span><span class="string"><font color="#0000ff">"center"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#698FC7"</font></span><span>><span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"tblhead"</font></span><span>><span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"STYLE2"</font></span><span>>商品类别设置 <span class="string"><font color="#0000ff">"?ToDo=add"</font></span><span>>添加一个新类别  </span></span><li class=""><span>            </span></li>
<li class="alt"><span>          </span></li>
<li class=""><span>       </span></li>
<li class="alt"><span>       <span class="string"><font color="#0000ff">"100%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#cccccc"</font></span><span> cellspacing=</span><span class="string"><font color="#0000ff">"1"</font></span><span> cellpadding=</span><span class="string"><font color="#0000ff">"3"</font></span><span>>  </span></span></li>
<li class=""><span>         <span class="string"><font color="#0000ff">"#F9F9F9"</font></span><span>>  </span></span></li>
<li class="alt"><span>           <span class="string"><font color="#0000ff">"6%"</font></span><span> height=</span><span class="string"><font color="#0000ff">"21"</font></span><span>>ID  </span></span></li>
<li class=""><span>           <span class="string"><font color="#0000ff">"49%"</font></span><span>>类别名称  </span></span></li>
<li class="alt"><span>           <span class="string"><font color="#0000ff">"14%"</font></span><span>>排序  </span></span></li>
<li class=""><span>           <span class="string"><font color="#0000ff">"31%"</font></span><span>>操作  </span></span></li>
<li class="alt"><span>           </span></li>
<li class=""><span>   <li class="alt"><span>         </span></li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select * from b_mtype order by rootid,orders"</font></span><span>);  </span>
</li></span></li>
<li class="alt">
<span>   </span><span class="keyword"><strong><font color="#006699">while</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$query</font></span><span>))  </span>
</li></span><li class=""><span>   {  </span></li>
<li class="alt"><span>     </span></li>
<li class=""><span>   ?>  </span></li>
<li class="alt"><span>           </span></li>
<li class=""><span>           <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typeid"</font></span><span>];?>  </span></span><li class="alt"><span>           <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>]>0) {  </span></span><li class="">
<span>                      </span><span class="keyword"><strong><font color="#006699">for</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$i</font></span><span>=1;</span><span class="vars"><font color="#dd0000">$i</font></span><span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>];</span><span class="vars"><font color="#dd0000">$i</font></span><span>++){ </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">" "</font></span><span>;}  </span></span>
</li>
<li class="alt"><span>     }?>  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>       <span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"child"</font></span><span>]>0) { </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"+"</font></span><span>;}</span><span class="keyword"><strong><font color="#006699">else</font></strong></span><span> {</span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"-"</font></span><span>;}?>   </span></span></li>
<li class=""><span>       <span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"parentid"</font></span><span>]==0) { </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;}?>  </span></span></li>
<li class="alt"><span>       <span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typename"</font></span><span>];?>  </span></span></li>
<li class=""><span>       <span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"child"</font></span><span>]>0) {?>(<span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"child"</font></span><span>];?>)  </span></span><li class="alt"><span>           <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"orders"</font></span><span>];?>  </span></span><li class=""><span>           <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="string"><font color="#0000ff">"?ToDo=add&editid=</font></span><span>typeid</span><span class="string"><font color="#0000ff">"];?>"</font></span><span>>添加子类   </span></span><li class="alt"><span>     | <span class="string"><font color="#0000ff">"?ToDo=edit&editid=</font></span><span>typeid</span><span class="string"><font color="#0000ff">"]?>"</font></span><span>>编辑类别   </span></span></li>
<li class=""><span>            |   <span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"child"</font></span><span>]==0){?><span class="string"><font color="#0000ff">"?ToDo=del&editid=</font></span><span>typeid</span><span class="string"><font color="#0000ff">"];?>"</font></span><span> onClick=</span><span class="string"><font color="#0000ff">"{if(confirm('删除类别时,该类别下的所有产品将一并被删除,确定删除吗?')){return true;}return false;}"</font></span><span>>删除类别<span class="keyword"><strong><font color="#006699">else</font></strong></span><span>{?><span class="string"><font color="#0000ff">"#"</font></span><span> onClick=</span><span class="string"><font color="#0000ff">"{if(confirm('该类别含有下属类别,必须先删除其下属类别方能删除本类别!')){return true;}return false;}"</font></span><span>>删除类别   </span></span><li class="alt"><span>           </span></li>
<li class=""><span>   <li class="alt"><span>   }  </span></li>
<li class=""><span>   ?>  </span></li>
<li class="alt"><span>         </span></li>
<li class=""><span>       </span></li>
<li class="alt"><span>     </span></li>
<li class=""><span>   </span></li>
<li class="alt"><span><li class="">
<span>     </span><span class="keyword"><strong><font color="#006699">break</font></strong></span><span>;  </span>
</li></span></li>
<li class="alt"><span>    }  </span></li>
<li class=""><span>    ?>  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span> </span></li>
<li class="alt"><span><span class="comment"><font color="#008200">///增加类别 </font></span><span> </span></span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">function</font></strong></span><span> add(){  </span>
</li></span></li>
<li class="alt">
<span>    @</span><span class="vars"><font color="#dd0000">$editid</font></span><span>=</span><span class="vars"><font color="#dd0000">$_REQUEST</font></span><span>[</span><span class="string"><font color="#0000ff">"editid"</font></span><span>];  </span>
</li></span><li class=""><span>?>  </span></li>
<li class="alt"><span>    <span class="string"><font color="#0000ff">"form1"</font></span><span> method=</span><span class="string"><font color="#0000ff">"post"</font></span><span> action=</span><span class="string"><font color="#0000ff">"?ToDo=saveadd"</font></span><span>>  </span></span></li>
<li class=""><span>         <span class="string"><font color="#0000ff">"90%"</font></span><span>   align=</span><span class="string"><font color="#0000ff">"center"</font></span><span> cellpadding=</span><span class="string"><font color="#0000ff">"3"</font></span><span> cellspacing=</span><span class="string"><font color="#0000ff">"1"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#CCCCCC"</font></span><span>>  </span></span></li>
<li class="alt"><span>           <span class="string"><font color="#0000ff">"#CCCCCC"</font></span><span>>  </span></span></li>
<li class=""><span>             <span class="string"><font color="#0000ff">"2"</font></span><span> align=</span><span class="string"><font color="#0000ff">"center"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#698FC7"</font></span><span>><span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"STYLE2"</font></span><span>>创建新的类别  </span></span><li class="alt"><span>                          </span></li>
<li class=""><span>             </span></li>
<li class="alt"><span>             <span class="string"><font color="#0000ff">"25%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>类别名称:  </span></span></li>
<li class=""><span>             <span class="string"><font color="#0000ff">"75%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="string"><font color="#0000ff">"typename"</font></span><span> type=</span><span class="string"><font color="#0000ff">"text"</font></span><span> id=</span><span class="string"><font color="#0000ff">"typename"</font></span><span>>  </span></span><li class="alt"><span>             </span></li>
<li class=""><span>             </span></li>
<li class="alt"><span>            <span class="string"><font color="#0000ff">"25%"</font></span><span> height=30 bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>所属类别  </span></span></li>
<li class=""><span>            <span class="string"><font color="#0000ff">"75%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>   </span></span></li>
<li class="alt"><span>               </span></li>
<li class=""><span>             <span class="string"><font color="#0000ff">"0"</font></span><span>>做为主类别  </span></span></li>
<li class="alt"><span>             <li class="">
<span>     </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select * from b_mtype order by rootid,orders"</font></span><span>);     </span>
</li></span></li>
<li class="alt">
<span>     </span><span class="keyword"><strong><font color="#006699">while</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$query</font></span><span>)){ ?>  </span>
</li></span></li>
<li class=""><span>             <span class="string"><font color="#0000ff">"</font></span><span>typeid</span><span class="string"><font color="#0000ff">"]?>"</font></span><span> <span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$editid</font></span><span> == </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">'typeid'</font></span><span>]){ </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">" selected"</font></span><span>; }?>>  </span></span><li class="alt"><span>             <span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>]>0) {  </span></span></li>
<li class="">
<span>               </span><span class="keyword"><strong><font color="#006699">for</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$i</font></span><span>=1;</span><span class="vars"><font color="#dd0000">$i</font></span><span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>];</span><span class="vars"><font color="#dd0000">$i</font></span><span>++)  </span></span>
</li>
<li class="alt"><span>      {  </span></li>
<li class="">
<span>        </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"-"</font></span><span>;  </span>
</li></span></li>
<li class="alt"><span>          }  </span></li>
<li class=""><span>         </span></li>
<li class="alt"><span>              }?>  </span></li>
<li class=""><span>              <span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typename"</font></span><span>]?>  </span></span></li>
<li class="alt"><span>             <li class=""><span>           }    </span></li>
<li class="alt"><span>              ?>  </span></li>
<li class=""><span>               </span></li>
<li class="alt"><span>               </span></li>
<li class=""><span>             </span></li>
<li class="alt"><span>             </span></li>
<li class=""><span>             <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>   </span></span></li>
<li class="alt"><span>             <span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>><span class="string"><font color="#0000ff">"submit"</font></span><span> name=</span><span class="string"><font color="#0000ff">"Submit"</font></span><span> value=</span><span class="string"><font color="#0000ff">"保存"</font></span><span>>  </span></span><li class=""><span>                 </span></li>
<li class="alt"><span>               <span class="string"><font color="#0000ff">"button"</font></span><span> name=</span><span class="string"><font color="#0000ff">"cancel"</font></span><span> id=</span><span class="string"><font color="#0000ff">"cancel"</font></span><span> value=</span><span class="string"><font color="#0000ff">"返回"</font></span><span> onclick=</span><span class="string"><font color="#0000ff">"history.go(-1);"</font></span><span> />  </span></span></li>
<li class=""><span>               </span></li>
<li class="alt"><span>             </span></li>
<li class=""><span>           </span></li>
<li class="alt"><span>  </span></li>
<li class=""><span>  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span><span class="comment"><font color="#008200">/////保存增加的类别 </font></span><span> </span></span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">function</font></strong></span><span> saveadd(){  </span>
</li></span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select typeid from b_mtype order by typeid desc limit 1"</font></span><span>);  </span>
</li></span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">while</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$query</font></span><span>)){  </span>
</li></span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (!</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typeid"</font></span><span>]){  </span>
</li></span><li class="">
<span>      </span><span class="vars"><font color="#dd0000">$postnum</font></span><span>=1;  </span>
</li></span></li>
<li class="alt"><span>    </span></li>
<li class="">
<span>}</span><span class="keyword"><strong><font color="#006699">else</font></strong></span><span>{  </span>
</li></span></li>
<li class="alt">
<span>      </span><span class="vars"><font color="#dd0000">$postnum</font></span><span>=</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typeid"</font></span><span>]+1;  </span>
</li></span></li>
<li class=""><span>    </span></li>
<li class="alt"><span>}     </span></li>
<li class=""><span>}  </span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(!</span><span class="vars"><font color="#dd0000">$postnum</font></span><span>) </span><span class="vars"><font color="#dd0000">$postnum</font></span><span>=1;  </span>
</li></span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$ntid</font></span><span>   =</span><span class="vars"><font color="#dd0000">$postnum</font></span><span>;  </span>
</li></span></li>
<li class="">
<span></span><span class="vars"><font color="#dd0000">$tn</font></span><span>     =</span><span class="vars"><font color="#dd0000">$_REQUEST</font></span><span>[</span><span class="string"><font color="#0000ff">"typename"</font></span><span>];  </span>
</li></span></li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$btype</font></span><span> =</span><span class="vars"><font color="#dd0000">$_REQUEST</font></span><span>[</span><span class="string"><font color="#0000ff">"btype"</font></span><span>];  </span>
</li></span><li class=""><span> </span></li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="comment"><font color="#008200">//echo $btype; </font></span><span> </span>
</li></span></li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$ntid</font></span><span>==</span><span class="string"><font color="#0000ff">""</font></span><span> </span><span class="keyword"><strong><font color="#006699">or</font></strong></span><span> </span><span class="vars"><font color="#dd0000">$tn</font></span><span>==</span><span class="string"><font color="#0000ff">""</font></span><span>)  </span>
</li></span></li>
<li class="alt"><span>{  </span></li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"alert('参数有误,请重新填写.!');"</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"location.href='?';"</font></span><span>;  </span>
</li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">die</font></strong></span><span>();  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$btype</font></span><span>!=0){  </span>
</li>
<li class=""><span>    </span></li>
<li class="alt">
<span>    </span><span class="vars"><font color="#dd0000">$result</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select rootid,typeid,depth,orders,parentstr from b_mtype where typeid='$btype'"</font></span><span>);  </span>
</li>
<li class="">
<span>    </span><span class="vars"><font color="#dd0000">$aa</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$result</font></span><span>);  </span>
</li>
<li class="alt">
<span>    </span><span class="vars"><font color="#dd0000">$rootid</font></span><span>=</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">'rootid'</font></span><span>];  </span>
</li>
<li class="">
<span>    </span><span class="comment"><font color="#008200">//echo "aaaaaaaaaaa"; </font></span><span> </span>
</li>
<li class="alt">
<span>    </span><span class="vars"><font color="#dd0000">$parentid</font></span><span>=</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">'typeid'</font></span><span>];  </span>
</li>
<li class="">
<span>    </span><span class="vars"><font color="#dd0000">$depth</font></span><span>=</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">'depth'</font></span><span>];  </span>
</li>
<li class="alt">
<span>    </span><span class="vars"><font color="#dd0000">$orders</font></span><span>=</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">'orders'</font></span><span>];  </span>
</li>
<li class="">
<span>    </span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>=</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">'parentstr'</font></span><span>];  </span>
</li>
<li class="alt">
<span>    </span><span class="comment"><font color="#008200">//echo $rootid; </font></span><span> </span>
</li>
<li class=""><span> </span></li>
<li class="alt">
<span>    </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span>((</span><span class="vars"><font color="#dd0000">$aa</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>]+1)>20){   </span><span class="keyword"><strong><font color="#006699">die</font></strong></span><span>(</span><span class="string"><font color="#0000ff">"本分类限制最多只能有20级分类"</font></span><span>); }  </span>
</li>
<li class=""><span> </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$ntid</font></span><span> == </span><span class="vars"><font color="#dd0000">$btype</font></span><span>)  </span>
</li>
<li class=""><span>{  </span></li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"alert('您所指定的typeid值重复!');"</font></span><span>;  </span>
</li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"location.href='?';"</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">die</font></strong></span><span>();  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$btype</font></span><span>!=0){  </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$depth</font></span><span>=</span><span class="vars"><font color="#dd0000">$depth</font></span><span>+1;  </span>
</li>
<li class="alt">
<span>   </span><span class="vars"><font color="#dd0000">$rootid</font></span><span>=</span><span class="vars"><font color="#dd0000">$rootid</font></span><span>;  </span>
</li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$orders</font></span><span> =</span><span class="vars"><font color="#dd0000">$ntid</font></span><span>;  </span>
</li>
<li class="alt">
<span>   </span><span class="vars"><font color="#dd0000">$parentid</font></span><span> =</span><span class="vars"><font color="#dd0000">$btype</font></span><span>;  </span>
</li>
<li class="">
<span>   </span><span class="comment"><font color="#008200">//$child = $child; </font></span><span> </span>
</li>
<li class="alt">
<span>   </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>==</span><span class="string"><font color="#0000ff">"0"</font></span><span>){  </span>
</li>
<li class="">
<span>      </span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>=</span><span class="vars"><font color="#dd0000">$btype</font></span><span>;  </span>
</li>
<li class="alt">
<span>   }</span><span class="keyword"><strong><font color="#006699">else</font></strong></span><span>{  </span>
</li>
<li class="">
<span>      </span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>=</span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>.</span><span class="string"><font color="#0000ff">","</font></span><span>.</span><span class="vars"><font color="#dd0000">$btype</font></span><span>;  </span>
</li>
<li class="alt"><span>   }  </span></li>
<li class=""><span> </span></li>
<li class="alt">
<span>}</span><span class="keyword"><strong><font color="#006699">else</font></strong></span><span>{  </span>
</li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$depth</font></span><span>=0;  </span>
</li>
<li class="alt">
<span>   </span><span class="vars"><font color="#dd0000">$rootid</font></span><span>=</span><span class="vars"><font color="#dd0000">$ntid</font></span><span>;  </span>
</li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$orders</font></span><span>=1;  </span>
</li>
<li class="alt">
<span>   </span><span class="vars"><font color="#dd0000">$parentid</font></span><span>=0;  </span>
</li>
<li class="">
<span>   </span><span class="vars"><font color="#dd0000">$child</font></span><span>=0;  </span>
</li>
<li class="alt">
<span>   </span><span class="vars"><font color="#dd0000">$parentstr</font></span><span>=0;  </span>
</li>
<li class=""><span>}  </span></li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="comment"><font color="#008200">//插入类别 </font></span><span> </span>
</li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"insert into b_mtype values('$ntid','$tn','$parentid','$parentstr','$depth','$rootid','','$orders')"</font></span><span>) ;  </span>
</li>
<li class="">
<span></span><span class="comment"><font color="#008200">//用于调试 echo "insert into b_mtype values('$ntid','$tn','$parentid','$parentstr','$depth','$rootid','','$orders')"; </font></span><span> </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$btype</font></span><span>!=0)  </span>
</li>
<li class="alt"><span>   {  </span></li>
<li class="">
<span>      </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$depth</font></span><span>>0)  </span>
</li>
<li class="alt"><span>      {  </span></li>
<li class="">
<span>         </span><span class="comment"><font color="#008200">//当上级分类深度大于0的时候要更新其父类或父类的父类)的版面数和相关排序 </font></span><span> </span>
</li>
<li class="alt">
<span>         </span><span class="keyword"><strong><font color="#006699">for</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$i</font></span><span>=1;</span><span class="vars"><font color="#dd0000">$i</font></span><span><span class="vars"><font color="#dd0000">$depth</font></span><span>;</span><span class="vars"><font color="#dd0000">$i</font></span><span>++){  </span></span>
</li>
<li class="">
<span>            </span><span class="comment"><font color="#008200">//更新其父类版面数 </font></span><span> </span>
</li>
<li class="alt">
<span>            </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$parentid</font></span><span>!=</span><span class="string"><font color="#0000ff">""</font></span><span>){  </span>
</li>
<li class="">
<span>               </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set child=child+1 where typeid='$parentid'"</font></span><span>);  </span>
</li>
<li class="alt"><span>            }  </span></li>
<li class="">
<span>            </span><span class="comment"><font color="#008200">//得到其父类的父类的版面ID </font></span><span> </span>
</li>
<li class="alt">
<span>            </span><span class="vars"><font color="#dd0000">$result</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select parentid from b_mtype where typeid='$parentid'"</font></span><span>);  </span>
</li>
<li class="">
<span>            </span><span class="vars"><font color="#dd0000">$par</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$result</font></span><span>);  </span>
</li>
<li class="alt"><span>    </span></li>
<li class="">
<span>            </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$par</font></span><span>[</span><span class="string"><font color="#0000ff">'parentid'</font></span><span>]!=</span><span class="string"><font color="#0000ff">""</font></span><span>){  </span>
</li>
<li class="alt">
<span>              </span><span class="vars"><font color="#dd0000">$parentid</font></span><span>=</span><span class="vars"><font color="#dd0000">$par</font></span><span>[</span><span class="string"><font color="#0000ff">'parentid'</font></span><span>];  </span>
</li>
<li class=""><span>            }  </span></li>
<li class="alt">
<span>            </span><span class="comment"><font color="#008200">//当循环次数大于1并且运行到最后一次循环的时候直接进行更新 </font></span><span> </span>
</li>
<li class="">
<span>            </span><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$i</font></span><span>==</span><span class="vars"><font color="#dd0000">$depth</font></span><span> && </span><span class="vars"><font color="#dd0000">$parentid</font></span><span>!=</span><span class="string"><font color="#0000ff">""</font></span><span>){  </span>
</li>
<li class="alt">
<span>              </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set child=child+1 where typeid='$parentid'"</font></span><span>);  </span>
</li>
<li class=""><span>            }  </span></li>
<li class="alt">
<span>          }</span><span class="comment"><font color="#008200">//for循环结束 </font></span><span> </span>
</li>
<li class="">
<span>          </span><span class="comment"><font color="#008200">//更新该版面排序以及大于本需要和同在本分类下的版面排序序号 </font></span><span> </span>
</li>
<li class="alt">
<span>          </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set orders=orders+1 where rootid='$rootid' and orders>'$orders'"</font></span><span>);  </span>
</li>
<li class="">
<span>          </span><span class="comment"><font color="#008200">//$orders1=$orders+1; </font></span><span> </span>
</li>
<li class="alt">
<span>          </span><span class="comment"><font color="#008200">//echo "orders1=".$orders1; </font></span><span> </span>
</li>
<li class="">
<span>          </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set orders='$orders'+1 where typeid='$ntid'"</font></span><span>);    </span>
</li>
<li class="alt"><span>    </span></li>
<li class="">
<span>        }</span><span class="keyword"><strong><font color="#006699">else</font></strong></span><span>{  </span><span class="comment"><font color="#008200">//对应if ($depth>0),当上级分类深度为0的时候只要更新上级分类版面数和该版面排序序号即可   </font></span><span> </span>
</li>
<li class="alt">
<span>        </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set child=child+1 where typeid='$btype'"</font></span><span>);  </span>
</li>
<li class="">
<span>        </span><span class="vars"><font color="#dd0000">$result</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select max(orders) from b_mtype where typeid='$ntid'"</font></span><span>);  </span>
</li>
<li class="alt">
<span>        </span><span class="vars"><font color="#dd0000">$ord</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$result</font></span><span>);     </span>
</li>
<li class="">
<span>        </span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"update b_mtype set orders='$ord[0]'+1 where typeid='$ntid'"</font></span><span>);  </span>
</li>
<li class="alt"><span>        }  </span></li>
<li class=""><span>      </span></li>
<li class="alt"><span>}  </span></li>
<li class=""><span>   </span></li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"alert('类别添加成功!');"</font></span><span>;  </span>
</li>
<li class="alt">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"location.href='?';"</font></span><span>;  </span>
</li>
<li class="">
<span></span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">""</font></span><span>;  </span>
</li>
<li class="alt"><span>}  </span></li>
<li class=""><span>?>  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span><span class="comment"><font color="#008200">////修改设置 </font></span><span> </span></span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">function</font></strong></span><span> edit(){  </span>
</li>
<li class="">
<span>   </span><span class="comment"><font color="#008200">//global $db,$editid,$tn,$arr; </font></span><span> </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="vars"><font color="#dd0000">$editid</font></span><span>=</span><span class="vars"><font color="#dd0000">$_REQUEST</font></span><span>[</span><span class="string"><font color="#0000ff">"editid"</font></span><span>];  </span>
</li>
<li class="alt"><span> </span></li>
<li class="">
<span></span><span class="vars"><font color="#dd0000">$result</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select * from b_mtype where typeid='$editid'"</font></span><span>);  </span>
</li>
<li class="alt">
<span></span><span class="vars"><font color="#dd0000">$tn</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$result</font></span><span>);  </span>
</li>
<li class=""><span>?>       </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"form2"</font></span><span> action =</span><span class="string"><font color="#0000ff">"?ToDo=saveedit"</font></span><span> method=</span><span class="string"><font color="#0000ff">"post"</font></span><span>>         </span></span></li>
<li class=""><span><span class="string"><font color="#0000ff">"hidden"</font></span><span> name=</span><span class="string"><font color="#0000ff">"editid"</font></span><span> value=</span><span class="string"><font color="#0000ff">""</font></span><span>>  </span></span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"90%"</font></span><span> border=</span><span class="string"><font color="#0000ff">"0"</font></span><span>   align=center cellpadding=</span><span class="string"><font color="#0000ff">"3"</font></span><span> cellspacing=</span><span class="string"><font color="#0000ff">"1"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#CCCCCC"</font></span><span>>  </span></span></li>
<li class=""><span>   </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"#698FC7"</font></span><span> </span><span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"STYLE2"</font></span><span>>编辑类别:<span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$tn</font></span><span>[</span><span class="string"><font color="#0000ff">"typename"</font></span><span>];?>  </span></span><li class=""><span>  </span></li>
<li class="alt"><span>   </span></li>
<li class=""><span><span class="string"><font color="#0000ff">"44%"</font></span><span> height=30 bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>类别名称  </span></span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"56%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>   </span></span></li>
<li class=""><span><span class="string"><font color="#0000ff">"text"</font></span><span> name=</span><span class="string"><font color="#0000ff">"typename"</font></span><span> size=</span><span class="string"><font color="#0000ff">"35"</font></span><span>   value=</span><span class="string"><font color="#0000ff">"</font></span><span>typename</span><span class="string"><font color="#0000ff">"];?>"</font></span><span>>  </span></span></li>
<li class="alt"><span>  </span></li>
<li class=""><span>  </span></li>
<li class="alt"><span> </span></li>
<li class=""><span>   </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"44%"</font></span><span> height=30 bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>所属类别  </span></span></li>
<li class=""><span>      <span class="keyword"><strong><font color="#006699">class</font></strong></span><span>=</span><span class="string"><font color="#0000ff">"STYLE1"</font></span><span>>特别提示:  </span></span></li>
<li class="alt"><span>    所属类别不能指定当前类别(即自己)为父类别  </span></li>
<li class=""><span>    所属类别不能指定当前类别的子类别为父类别  </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"56%"</font></span><span> bgcolor=</span><span class="string"><font color="#0000ff">"#FFFFFF"</font></span><span>>   </span></span></li>
<li class=""><span><span class="string"><font color="#0000ff">"class"</font></span><span>>  </span></span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">"0"</font></span><span>>做为主类别  </span></span></li>
<li class=""><span><li class="alt">
<span></span><span class="vars"><font color="#dd0000">$query</font></span><span>=mysql_query(</span><span class="string"><font color="#0000ff">"select * from b_mtype order by rootid,orders"</font></span><span>);  </span>
</li></span></li>
<li class=""><span> </span></li>
<li class="alt">
<span></span><span class="keyword"><strong><font color="#006699">while</font></strong></span><span>(</span><span class="vars"><font color="#dd0000">$arr</font></span><span>=mysql_fetch_array(</span><span class="vars"><font color="#dd0000">$query</font></span><span>))  </span>
</li></span></li>
<li class=""><span>{ ?>  </span></li>
<li class="alt"><span><span class="string"><font color="#0000ff">""</font></span><span> <span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$tn</font></span><span>[</span><span class="string"><font color="#0000ff">"parentid"</font></span><span>] == </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typeid"</font></span><span>]) { </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"selected"</font></span><span>; } ?>><span class="keyword"><strong><font color="#006699">if</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>]>0) {?>  </span></span><li class=""><span><span class="keyword"><strong><font color="#006699">for</font></strong></span><span> (</span><span class="vars"><font color="#dd0000">$i</font></span><span>=1;</span><span class="vars"><font color="#dd0000">$i</font></span><span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"depth"</font></span><span>];</span><span class="vars"><font color="#dd0000">$i</font></span><span>++){ </span><span class="func">echo</span><span> </span><span class="string"><font color="#0000ff">"-"</font></span><span>;}?>  </span></span><li class="alt"><span><span class="func">echo</span><span> </span><span class="vars"><font color="#dd0000">$arr</font></span><span>[</span><span class="string"><font color="#0000ff">"typename"</font></span><span>]?>  </span></span></li>
<li class=""><span><li class="alt"><span>}  </span></li>
<li class=""><span>?>  </span></li>
<li class="alt"><span>  </span></li>
<li class=""><span>  </span></li>
<li class="alt"><span>  </span></li>
<li class=""><span> </span></li>
<li class="alt"><span>   </span></li>
<li class=""><span><span class="string"><font color="#0000ff">"44%"</font></span><span> height=2</span></span></li></span></li></span></li></span></span></li>
</ol>
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板