PHP 運用concat的無限分類

來源:互聯網
上載者:User
PHP 使用concat的無限分類

?

?

一、資料庫設計:

?

?

-- -- Table structure for table `category`-- CREATE TABLE `category` (  `id` int(11) NOT NULL auto_increment,  `catpath` varchar(255) default NULL,  `name` varchar(255) default NULL,  PRIMARY KEY  (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=11 ;-- -- Dumping data for table `category`-- INSERT INTO `category` VALUES (1, '0', '網站首頁');INSERT INTO `category` VALUES (2, '0-1', 'Linux OS');INSERT INTO `category` VALUES (3, '0-1', 'Apache伺服器');INSERT INTO `category` VALUES (4, '0-1', 'MySQL資料庫');INSERT INTO `category` VALUES (5, '0-1', 'PHP指令碼語言');INSERT INTO `category` VALUES (6, '0-1-2', 'Linux 系統教程');INSERT INTO `category` VALUES (7, '0-1-2', 'Linux 網路技術');INSERT INTO `category` VALUES (8, '0-1-2', 'Linux 安全基礎');INSERT INTO `category` VALUES (9, '0-1-2-7', 'Linux LAMP');INSERT INTO `category` VALUES (10, '0-1-3-10', 'apache Server');

?

?

這裡說明下,catpath的-連結符號不是固定的,可以選擇,;等特殊符號。

二、 PHP代碼實現:

?

?

';*/        //第二種展示方法    $space = str_repeat ( '    ', count ( explode ( '-', $row ['abspath'] ) ) - 1 );    $option .= '' . $space . $row ['name'] . '';}echo '' . $option . '';?>

?

MySQL concat函數可以串連一個或者多個字串
select concat('顏','培','攀')
select `id`,`name`,concat(`id`,'-',`name`) as iname

?

?

?

關聯:

簡單的無限分級類 category, menus, jquery tree view?

?

?

?

?

?

?

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.