-
- 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.簡述論壇中無限分類的實現原理。
答:
-
-
/*
- 資料表結構如下:
- ATEATE TABLE `category` (
- `categoryID` smallint(5) unsigned NOT NULL auto_increment,
- `categoryParentID` smallint(5) unsigned NOT NULL default '0′,
- `categoryName` varchar(50) Ndefault '0′,
- `categoryName` varchar(50) Ndefault ' PRIMARY KEY (`categoryID`)
- ) ENGINE=MyISAM DEFAULT CHARSET=gbk;
INSERT INTO `category` ( `categoryParentID`, `categoryName`) VALUES(1, '二級類別'),
- (1, '二級類別'),
- (1, '二級類別'),
- ( 2, '三級類'),
- (2, '333332′),
- (2, '234234′),
- (3, 'aqqqqqd'),
- (4, '哈哈'),
- (5, '66333666′);
*/
//指定分類id變數$category_id,然後傳回該分類的所有子類別
- //$default_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 “
?> >
複製程式碼
-
-
班級美食
- {
- < ;p> function Get_Category($category_id = 0,$level = 0, $default_category = 0)
- {
- echo $category_id;
- $arr = array(
- '0′ => array (
- $arr>
- '0′ => array (
- '1′ => array('id' => 1, 'parent' => 0, 'name' => '1111'),
- '2' => array( 'id' => 2, '父項' => 0, '姓名' => '2222'),
- '4' => 陣列('id' => 4, '父項' = > 0, '姓名' => '4444')
- ),
- '1' => 陣列(
- '3' => 陣列('id' => 3, '父級=> 1, '姓名' => '333333'),
- '5' => 陣列('id' => 5, '父級' => 1, '姓名' => ; '555555')
- ),
' 3' => 陣列(
- '6' => 陣列('id' => 6, '父級=> 3, '姓名' => '66666'),
- '7' => 陣列( 'id' => 7, '父級' => 3, '姓名' => ; '77777')
- ),
- '4' => 陣列(
- '8' => 陣列( 'id' => 8, '父級' => 4, '姓名' => '8888'),
- '9' => 陣列('id' => 9, '父級' => 4, '名稱' => '9999')
- )
- );
if (!isset($arr[$category_id]))
- {
- return “ ”;
- }
foreach($arr[$category_id] AS $key =>; $cate)
- {
- if ($cate['id'] = = $default_category)
- {
- $txt = “}else{
- $txt = “}
0)
- {
- $txt1 = “>” 。 str_repeat(“-”, $level) 。 」 「。 $cate['名稱'] 。 “n”;
- }其他{
- $txt1 =“>” 。 $cate['名稱'] 。 「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;
- }
- }
- return $out;
- }
- }
- $ = $_GET['id'];
- echo “”;
- $c = new cate();
- //$c->Get_Category();
$ttt= $c ->getFlush ($id,'0′,'3′); echo $ttt; echo “”;?>
|