Home > Backend Development > PHP Tutorial > How to implement unlimited classification in php using concat, unlimited classification in php concat_PHP tutorial

How to implement unlimited classification in php using concat, unlimited classification in php concat_PHP tutorial

WBOY
Release: 2016-07-12 09:05:25
Original
974 people have browsed it

How to implement unlimited php classification using concat, php unlimited classification concat

1. Database design

--  
-- 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');  
Copy after login

As explained here, the - link symbol of catpath is not fixed, you can choose special symbols such as;

2. PHP code implementation

<&#63; 
$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 ) )  
{ 
  //第一种展示方法 
  //$space = str_repeat ( '    ', count ( explode ( '-', $row ['abspath'] ) ) - 1 ); 
  //echo $space . $row ['name'] . '<br>';*/ 
   
  //第二种展示方法 
  $space = str_repeat ( '    ', count ( explode ( '-', $row ['abspath'] ) ) - 1 ); 
  $option .= '<option value="' . $row ['id'] . '">' . $space . $row ['name'] . '</option>'; 
} 
echo '<select name="opt">' . $option . '</select>'; 
&#63;> 
Copy after login

MySQL concat function can connect one or more strings

select concat('颜','培','攀')
select `id`,`name`,concat(`id`,'-',`name`) as iname
Copy after login

The above is the entire content of this article. It introduces the use of concat in PHP to implement wireless classification. I hope it will be helpful to everyone's learning.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1068831.htmlTechArticleHow to implement unlimited classification in php using concat, php unlimited classification concat 1. Database design -- -- Table structure for table `category` -- CREATE TABLE `category` ( `id` int(11) NOT NULL...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template