-
CREATE TABLE likecate (
id INT UNSIGNED NOT NULL PRIMARY KEY,
path VARCHAR(200) NOT NULL DEFAULT '' COMMENT '全路徑',
catename VARCHAR(30) NOT NULL DEFAULT '' COMMENT '分類名',
cateorder INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '排序',
createtime INT UNSIGNED NOT NULL COMMENT '創(chuàng)建時間'
)ENGINE=MYISAM DEFAULT CHARSET=utf8;
INSERT INTO likecate VALUES
(1,'','手機',0,0),
(2,'1','功能手機',0,0),
(3,'1,2','老人手機',0,0),
(4,'1,2','兒童手機',0,0),
(5,'1','智能手機',0,0),
(6,'1,5','Android手機',0,0),
(7,'1,5','iOS手機',0,0),
(8,'1,5','winphoto手機',0,0),
(9,'1,2,4','色盲手機',0,0),
(10,'1,2,3','大字手機',0,0),
(11,'12','臺式機',0,0),
(12,'','電腦',0,0),/*經(jīng)過一些增刪操作,有可能父類id大于子類id*/
(13,'12,11','一體機',0,0),
(14,'12,11','非一體機',0,0),
(15,'12','筆記本',0,0);查看全部 -
CREATE TABLE IF NOT EXISTS `deepcate` (
`id` int(4) NOT NULL,
`pid` int(11) NOT NULL,
`catename` varchar(30) NOT NULL,
`cateorder` int(11) unsigned NOT NULL DEFAULT '0',
`createtime` int(10) NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='cms類型表';
--
-- 轉存表中的數(shù)據(jù) `deepcate`
--
INSERT INTO `deepcate` (`id`, `pid`, `catename`, `cateorder`, `createtime`) VALUES
(1, 0, '新聞', 0, 0),
(2, 0, '圖片', 0, 0),
(3, 1, '國內(nèi)新聞', 0, 0),
(4, 1, '國際新聞', 0, 0),
(5, 3, '北京新聞', 0, 0),
(6, 4, '美國新聞', 0, 0),
(7, 2, '美女圖片', 0, 0),
(8, 2, '風景圖片', 0, 0),
(9, 7, '日韓明星', 0, 0),
(10, 9, '日本AV', 0, 0);查看全部 -
輸出下拉菜單
查看全部 -
輸出下拉菜單查看全部
-
輸出下拉菜單查看全部
-
查詢結構代碼
查看全部 -
查詢結構代碼
查看全部 -
數(shù)據(jù)表結構
查看全部 -
面包屑分類
<?php require_once('./db.php'); //面包屑類型分類 $id?=?isset($_GET['id'])?$_GET['id']:false; if?(!$id){ ????echo?'<script>window.location.href="./03.php?id=1"</script>'; }else{ ????function?getCatePath($id=1,&$arr?=?[]){ ????????$func?=?__FUNCTION__; ????????if?(!$id){ ????????????dir('不能為0'); ????????} ????????$sql?=?"select?*?from?deepcate?where?id=$id"; ????????$res?=?mysqli_fetch_assoc(query($sql)); ????????$arr[]?=?$res; ????????if?($res['pid']){ ????????????$func($res['pid'],$arr); ????????} ????????return?$arr; ????} ????$arr?=?array_reverse(getCatePath($id)); ????if?(empty($arr[0]['id'])){ ????????die('id無效'); ????}else{ ????????foreach?($arr?as?$key=>$val){ ????????????echo?"<a?href='./03.php?id={$arr[$key]['id']}'>{$arr[$key]['catename']}</a>".">"; ????????} ????} }
查看全部 -
初始化數(shù)據(jù)庫
<?php header("Content-type:?text/html;?charset=utf-8"); $db_name?=?'infiniteclass'; $host?=?'localhost'; $user?=?'root'; $password?=?'123456'; $link?=?null; //初始化數(shù)據(jù)庫連接 function?initDB($db_name,$host,$user,$password){ ????global?$link; ????$link?=?mysqli_connect($host,$user,$password,$db_name); ????if?(!$link){ ????????die('數(shù)據(jù)庫鏈接失敗'); ????} ????mysqli_query($link,'set?names?utf8'); } //查詢函數(shù) function?query($str){ ????global?$link; ????$res?=?mysqli_query($link,$str); ????if?(!$res){ ????????return?'查詢失敗'; ????}else{ ????????return?$res; ????} } initDB($db_name,$host,$user,$password);
查看全部 -
遞歸分類原理
查看全部 -
遞歸筆記
查看全部 -
無限級?常見的幾種實現(xiàn)
查看全部 -
學習查看全部
-
無限極分類兩種方式:遞歸無限極分類,全路徑無限極分類查看全部
-
yufayaodian查看全部
-
<?php include('connect.php'); header("Content-type: text/html; charset=utf-8"); //得到一個結果集數(shù)組 function getCatePath($cid,&$result=array()){ $sql="SELECT * FROM deepcate WHERE id=$cid"; $rs=mysql_query($sql); $row=mysql_fetch_assoc($rs); //print_r($row); if($row){ $result[]=$row; getCatePath($row['pid'],$result); } krsort($result);//krsort對數(shù)組按鍵名逆向排序 return $result; } //$res=getCatePath(10); //print_r($res); function displayCatePath($cid,$url="link.php?cid="){ $res=getCatePath($cid); $str=''; foreach ($res as $key => $value) { $str.="<a href='{$url}{$value['id']}'>{$value['catename']}</a>>"; } return $str; } echo displayCatePath(10,'link.php?page=2&id=');查看全部
-
遞歸實現(xiàn)方法查看全部
-
$res是個結果集,mysql_fetch_assoc解析返回一個一維數(shù)組,$result為二維數(shù)組,這個是原生寫法,在沒有框架情況下寫法查看全部
-
實現(xiàn)方式查看全部
-
數(shù)據(jù)表設計查看全部
-
遞歸無限分類原理查看全部
舉報