- Function my_scandir ($ dir)
- {
- $ Files = array ();
- If ($ handle = opendir ($ dir )){
- While ($ file = readdir ($ handle ))! = False ){
- If ($ file! = "..." & $ File! = ".") {
- If (is_dir ($ dir. "/". $ file )){
- $ Files [$ file] = scandir ($ dir. "/". $ file );
- } Else {
- $ Files [] = $ file;
- }
- }
- }
- Closedir ($ handle );
- Return $ files;
- }
- }
14. briefly describe the implementation principles of unlimited classification in the forum. A:
/*
- The data table structure is as follows:
- Create table 'Category '(
- 'Categoryid' smallint (5) unsigned not null auto_increment,
- 'Categoryparentid' smallint (5) unsigned not null default '0 ′,
- 'Categoryname' varchar (50) not null default ",
- Primary key ('categoryid ')
- ) ENGINE = MyISAM default charset = gbk;
Insert into 'category' ('categoryparentid', 'categoryname') VALUES
- (0, 'level 1 category '),
- (1, 'level 2 category '),
- (1, 'level 2 category '),
- (1, 'level 2 category '),
- (2, 'third-level category '),
- (2, '000000 ′),
- (2, '000000 ′),
- (3, 'aqqqqqd '),
- (4, 'Haha '),
- (5, '000000 ′);
*/
// Specify the category id variable $ category_id and return all subclasses of the category
- // $ Default_category is the default selected category.
- Function Get_Category ($ category_id = 0, $ level = 0, $ default_category = 0)
- {
- Global $ DB;
- $ SQL = "SELECT * FROM category ORDER BY categoryID DESC ";
- $ Result = $ DB-> query ($ SQL );
- While ($ rows = $ DB-> fetch_array ($ result ))
- {
- $ Category_array [$ rows [categoryParentID] [$ rows [categoryID] = array ('id' => $ rows [categoryID], 'parent' => $ rows [categoryParentID], 'name' => $ rows
[CategoryName]);
- }
- If (! Isset ($ category_array [$ category_id])
- {
- Return "";
- }
- Foreach ($ category_array [$ category_id] AS $ key => $ category)
- {
- If ($ category ['id'] = $ default_category)
- {
- Echo"} Else
- {
- Echo"}
If ($ level> 0)
- {
- Echo ">". str_repeat ("", $ level). "". $ category ['name']. "\ n ";
- }
- Else
- {
- Echo ">". $ category ['name']. "\ n ";
- }
- Get_Category ($ key, $ level + 1, $ default_category );
- }
- Unset ($ category_array [$ category_id]);
- }
/*
- The array format returned by the function is as follows:
- Array
- (
- [1] => Array ([id] => 1 [name] => level 1 category [level] => 0 [ParentID] => 0)
- [4] => Array ([id] => 4 [name] => level 2 category [level] => 1 [ParentID] => 1)
- [9] => Array ([id] => 9 [name] => haha [level] => 2 [ParentID] => 4)
- [3] => Array ([id] => 3 [name] => level 2 category [level] => 1 [ParentID] => 1)
- [8] => Array ([id] => 8 [name] => aqqqqqd [level] => 2 [ParentID] => 3)
- [2] => Array ([id] => 2 [name] => level 2 category [level] => 1 [ParentID] => 1)
- [7] => Array ([id] => 7 [name] => 234234 [level] => 2 [ParentID] => 2)
- [6] => Array ([id] => 6 [name] => 333332 [level] => 2 [ParentID] => 2)
- [5] => Array ([id] => 5 [name] => level 3 category [level] => 2 [ParentID] => 2)
- [10] => Array ([id] => 10 [name] => 66333666 [level] => 3 [ParentID] => 5)
- )
- */
- // Specify the Category id and return the array
- Function Category_array ($ category_id = 0, $ level = 0)
- {
- Global $ DB;
- $ SQL = "SELECT * FROM category ORDER BY categoryID DESC ";
- $ Result = $ DB-> query ($ SQL );
- While ($ rows = $ DB-> fetch_array ($ result ))
- {
- $ Category_array [$ rows ['categoryparentid'] [$ rows ['categoryid'] = $ rows;
- }
Foreach ($ category_array AS $ key => $ val)
- {
- If ($ key = $ category_id)
- {
- Foreach ($ val AS $ k => $ v)
- {
- $ Options [$ k] =
- Array (
- 'Id' => $ v ['categoryid'], 'name' => $ v ['categoryname'], 'level' => $ level, 'parentid' => $ v ['categoryparentid']
- );
$ Children = Category_array ($ k, $ level + 1 );
If (count ($ children)> 0)
- {
- $ Options = $ options + $ children;
- }
- }
- }
- }
- Unset ($ category_array [$ category_id]);
- Return $ options;
- }
- ?>
Class cate
- {
Function Get_Category ($ category_id = 0, $ level = 0, $ default_category = 0)
- {
- Echo $ category_id;
- $ Arr = array (
- '0' => array (
- '1' => array ('id' => 1, 'parent' => 0, 'name' => '123 ′),
- '2' => array ('id' => 2, 'parent' => 0, 'name' => '123 ′),
- '4' => array ('id' => 4, 'parent' => 0, 'name' => '123 ′)
- ),
- '1' => array (
- '3' => array ('id' => 3, 'parent' => 1, 'name' => '123 ′),
- '5' => array ('id' => 5, 'parent' => 1, 'name' => '123 ′)
- ),
'3' => array (
- '6' => array ('id' => 6, 'parent' => 3, 'name' => '123 ′),
- '7' => array ('id' => 7, 'parent' => 3, 'name' => '123 ′)
- ),
- '4' => array (
- '8' => array ('id' => 8, 'parent' => 4, 'name' => '123 ′),
- '9' => array ('id' => 9, 'parent' => 4, 'name' => '123 ′)
- )
- );
If (! Isset ($ arr [$ category_id])
- {
- Return "";
- }
Foreach ($ arr [$ category_id] AS $ key => $ cate)
- {
- If ($ cate ['id'] = $ default_category)
- {
- $ Txt ="} Else {
- $ Txt ="}
If ($ level> 0)
- {
- $ Txt1 = ">". str_repeat ("-", $ level). "". $ cate ['name']. "\ n ";
- } Else {
- $ Txt1 = ">". $ cate ['name']. "\ n ";
- }
- $ Val = $ txt. $ txt1;
- Echo $ val;
- Self: Get_Category ($ key, $ level + 1, $ default_category );
- }
- }
Function getFlush ($ category_id = 0, $ level = 0, $ default_category = 0)
- {
- Ob_start ();
- Self: Get_Category ($ category_id, $ level, $ default_category );
- $ Out = ob_get_contents ();
- Ob_end_clean ();
- Return $ out;
- }
- }
- $ Id = $ _ GET ['id'];
- Echo "";
- $ C = new cate ();
- // $ C-> Get_Category ();
- $ Ttt = $ c-> getFlush ($ id, '0', '3 ′);
- Echo $ ttt;
- Echo "";
- ?>
|