當前位置:法律諮詢服務網 - 企業資訊 - 誰有建公司部門的樹形結構的php的源代碼?要可以建三級部門

誰有建公司部門的樹形結構的php的源代碼?要可以建三級部門

存儲結構很簡單,主要是排序後顯示。

給妳示例代碼。

<?PHP

/*

CREATE TABLE `category` (

`categoryID` int(10) unsigned NOT NULL auto_increment,

`categoryParentID` int(10) unsigned NOT NULL default '0',

`categoryName` varchar(50) NOT NULL default '',

KEY `cate_id` (`categoryID`)

) TYPE=MyISAM AUTO_INCREMENT=11 ;

#

# 導出表中的數據 `category`

#

INSERT INTO `category` S (1, 0, '壹級類別1');

INSERT INTO `category` S (2, 1, '二級類別1');

INSERT INTO `category` S (3, 1, '二級類別2');

INSERT INTO `category` S (4, 1, '二級類別3');

INSERT INTO `category` S (5, 2, '三級類別21');

INSERT INTO `category` S (6, 2, '三級類別22');

INSERT INTO `category` S (7, 2, '三級類別23');

INSERT INTO `category` S (8, 3, 'rfwesdfsd');

INSERT INTO `category` S (9, 4, '54534w43');

INSERT INTO `category` S (10, 5, '66666');

*/

mysql_connect( "localhost", 'root', '' );

mysql_select_db( "test" );

$cate_table = "category";

_GetCategory( $category_id = 0, $depth = 1 )

{

global $cate_table;

$sql = "SELECT * FROM $cate_table ORDER BY categoryID DESC";

$result = mysql_query( $sql );

while ( $row = mysql_fetch_array( $result ) )

{

$array[$row[categoryParentID]][$row[categoryID]]

= array(

'id' => $row[categoryID],

'parent' => $row[categoryParentID],

'name' => $row[categoryName]

);

}

if ( !isset( $array[$category_id] ) )

{

return "";

}

foreach( $array[$category_id] AS $key => $category )

{

echo " <OPTION =".$category['id']." ";

if ( $category['parent'] == 0 )

{

echo " class='main' ";

}

if ( $depth > 1 )

{

echo ">" . str_repeat( "--", $depth - 1 ) . " " . $category['name'] . "</option>n";

}

else

{

echo ">" . $category['name'] . "</option>\n";

}

_GetCategory( $key, $depth + 1 );

}

unset( $array[$category_id] );

}

>

<select name="categoryID">

<option selected ="">-------------</option>

<?=_GetCategory();?>

</select>

  • 上一篇:江蘇壹男子花8000多元在網上買駕照被抓。賣家應該承擔什麽樣的責任?
  • 下一篇:天眼能查個人信息嗎,社工庫可以查到個人信息嗎
  • copyright 2024法律諮詢服務網