First, the database design
---
table structure for table ' category '-
-
CREATE Table ' category ' (
' id ' int (one) not NULL Auto_increme NT,
' 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 '-
-
inserts into ' category ' VALUES (1, ' 0 ', ' homepage ');
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 Tutorial ');
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 (Ten, ' 0-1-3-10 ', ' Apache Server ');
In this note, the Catpath-link symbol is not fixed, you can choose, such as special symbols.
Second, the 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 Presentation method
//$space = Str_repeat (', Count (explode) (' -', $row [' Abspath '])-1);
Echo $space. $row [' name ']. ' <br> '//
Second Presentation method
$space = Str_repeat (', Count (Explode ('-', $row [' Abspath '])-1);
$option. = ' <option value= '. $row [' id ']. ' > '. $space. $row [' name ']. ' </option> ';
}
Echo ' <select name= ' opt ' > '. $option. ' </select> ';
The MySQL concat function can connect one or more strings
Select Concat (' Yan ', ' pei ', ' Climb ')
select ' id ', ' name ', concat (' id ', '-', ' name ') as Iname
The above is the whole content of this article, introduced the PHP uses concat realizes the wireless classification, hoped for everybody's study to have the help.