PHP-based concat for unlimited classification

Source: Internet
Author: User
Tags security essentials
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.