This article describes how to use concat for php unlimited classification. For more information, see
This article describes how to use concat for php unlimited classification. For more information, see
-- 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', 'website'); insert into 'category' VALUES (2, '0-1', 'linux OS '); INSERT INTO 'category 'values (3, '0-1', 'apache Server '); insert into 'category 'values (4, '0-1', 'mysql database'); insert into 'category 'values (5, '0-1 ', 'php scripting language '); insert into 'category' VALUES (6, '0-1-2', 'linux system example'); insert into 'category' VALUES (7, '0-1-2 ', 'linux Network Technology'); insert into 'category 'values (8, '0-1-2 ', 'linux Security Basics '); insert into 'category 'values (9, '0-1-2-7 ', 'linux LAMP'); insert into 'category 'values (10, '0-1-3-10 ', 'apache Server ');
Here, the-link symbol of catpath is not fixed and can be selected, and other special symbols.
Ii. PHP code implementation
<? $ Conn = mysql_connect ('localhost', 'root', 'root'); mysql_select_db ('test', $ conn); mysql_query ('set names utf8 '); $ SQL = "select id, concat (catpath, '-', id) as abspath, name from category order by abspath"; $ query = mysql_query ($ SQL ); while ($ row = mysql_fetch_array ($ query) {// first display method // $ space = str_repeat ('', count (explode ('-', $ row ['abspath'])-1); // echo $ space. $ row ['name'].'
'; * // Second display method $ space = str_repeat ('', count (explode ('-', $ row ['abspath'])-1 ); $ option. =''. $ Space. $ row ['name'].'';} Echo''. $ Option .'';?>
The MySQL concat function can be used to connect one or more strings.
Select concat ('yan ', 'pei', 'pan ') select 'id', 'name', concat ('id','-', 'name') as iname