• 欢迎访问开心洋葱网站,在线教程,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站,欢迎加入开心洋葱 QQ群
  • 为方便开心洋葱网用户,开心洋葱官网已经开启复制功能!
  • 欢迎访问开心洋葱网站,手机也能访问哦~欢迎加入开心洋葱多维思维学习平台 QQ群
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏开心洋葱吧~~~~~~~~~~~~~!
  • 由于近期流量激增,小站的ECS没能经的起亲们的访问,本站依然没有盈利,如果各位看如果觉着文字不错,还请看官给小站打个赏~~~~~~~~~~~~~!

如何使用php、html、mysql构建一个多重分类选择列表

JavaScript 水墨上仙 1569次浏览

不适用javascript,完全通过php实现多级列表选择,列表数据从数据库获取

A very simple way to build and do a hierarchical html categories browser
 without javascript , just using html php and mySql
<? 
/* 
# 
# Table structure for table 'res_cat' 
# 
CREATE TABLE res_cat ( 
   ID int(32) DEFAULT '0' NOT NULL , 
   ID_uname char(40) NOT NULL, 
   UNIQUE ID (ID) 
); 
# 
# Dumping data for table 'res_cat' 
# 
INSERT INTO res_cat VALUES( '1', 'head1'); 
INSERT INTO res_cat VALUES( '101', 'cat11'); 
INSERT INTO res_cat VALUES( '102', 'cat12'); 
INSERT INTO res_cat VALUES( '103', 'cat13'); 
INSERT INTO res_cat VALUES( '10101', 'subcat111'); 
INSERT INTO res_cat VALUES( '10102', 'subcat112'); 
INSERT INTO res_cat VALUES( '10103', 'subcat113'); 
INSERT INTO res_cat VALUES( '1010101', 'subcat1111'); 
INSERT INTO res_cat VALUES( '1010102', 'subcat1112'); 
INSERT INTO res_cat VALUES( '1010103', 'subcat1113'); 
INSERT INTO res_cat VALUES( '10201', 'subcat121'); 
INSERT INTO res_cat VALUES( '10202', 'subcat122'); 
INSERT INTO res_cat VALUES( '10203', 'subcat123'); 
INSERT INTO res_cat VALUES( '10301', 'subcat131'); 
INSERT INTO res_cat VALUES( '10302', 'subcat132'); 
INSERT INTO res_cat VALUES( '10303', 'subcat133'); 
INSERT INTO res_cat VALUES( '2', 'head2'); 
INSERT INTO res_cat VALUES( '201', 'cat21'); 
INSERT INTO res_cat VALUES( '202', 'cat22'); 
INSERT INTO res_cat VALUES( '203', 'cat33'); 
etc ... 
*/ 
$mysql_link = mysql_connect("localhost", "user", "passwd"); 
mysql_select_db("res_cat", $mysql_link); 
echo "<html><body>" ; 
function listrub ($id , $exploseID   ) 
{ 
global $PHP_SELF ; 
global $mysql_link  ; 
$maxi = ($id*100)+100 ; 
$mini = $id*100 ; 
$query = "SELECT * FROM res_cat  where ID < $maxi and ID >  $mini    " ;   
echo "<ol>"; 
if(      $mysql_result = mysql_query($query , $mysql_link)   ) 
{ 
while ($row = mysql_fetch_object($mysql_result)) 
    { 
// you have to link some action on leaves of course 
echo "<li> <a href='$PHP_SELF?ID_rub=$row->ID' >   $row->ID_uname </a>  </li> " ; 
$testID = ($exploseID - ($exploseID  %100 ))/100 ; //  WARNING this is ugly .. only 3 level 
if ( $testID == $row->ID || $exploseID == $row->ID) 
         { 
         listrub ($row->ID , $exploseID ) ; 
        } 
    } 
} 
echo "</ol>"; 
} 
$father =999999999;  // a big number   
// get the grand...grand father 
if ( $ID_rub >100 ) 
{ 
$father = $ID_rub ; 
while ( $father >100 )    { $father= ( $father - ( $father %100) )/100 ; } 
} 
else{$father= $ID_rub ;} 
listrub ($father , $ID_rub ,$mysql_link ) ;   
echo "</body></html>"; 
?> 


开心洋葱 , 版权所有丨如未注明 , 均为原创丨未经授权请勿修改 , 转载请注明如何使用php、html、mysql构建一个多重分类选择列表
喜欢 (0)
加载中……