This article mainly introduces how PHP unlimited classification using CONCAT is implemented, the need for friends can refer to the following
First, the database design
---- table structure for table ' category '-- CREATE Table ' category ' ( ' id ' int (one) ' Not NULL auto_increment,< c3/> ' catpath ' varchar (255) default NULL, ' name ' varchar (255) default NULL, PRIMARY KEY (' id ')) Engine=myisam DEF Ault Charset=utf8 auto_increment=11; --- dumping data for table ' category ' – INSERT into ' category ' VALUES (1, ' 0 ', ' home page '); 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 essentials '); INSERT into ' category ' VALUES (9, ' 0-1-2-7 ', ' Linux LAMP '); INSERT into ' category ' VALUES (' 0-1-3-10 ', ' Apache Server ');
Here, the Catpath-link symbol is not fixed, you can choose, and so on special symbols.
Second, the implementation of PHP code
<? $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 the category order by Abspath"; $query = mysql_query ($sql); while ($row = Mysql_fetch_array ($query)) { //The first method of presentation //$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> ';?>
MySQL concat function can connect one or more strings
Select Concat (' Yan ', ' pui ', ' plansee ') Select ' id ', ' name ', concat (' id ', '-', ' name ') as Iname
Summary: The above is the entire content of this article, I hope to be able to help you learn.