Unlimited classification-Summary

Source: Internet
Author: User

PHP code: // unlimited classification-path // principle: splits the path to obtain all desired PIDs and IDs. The path is a field in the design table, contains a series of IDs from the ancestor id to the parent id // This method, whether viewed or deleted or other operations, you only need to execute an SQL statement once to achieve the desired results. // This method is also preferred, because my principle is that recursion is not used, instead of recursion $ link = mysql_connect ('localhost', 'username, 'Password'); if (mysql_errno () {echo 'database Connection Failed :'. mysql_error ();} mysql_select_db ('db _ kind'); mysql_set_charset ('utf8'); // concat (), concatenate a string into a new string // the following code completes an infinite classification of reality $ SQL = "select concat (path, '-', Id) as conpath, id, name, path from wx_kind order by conpath "; $ result = mysql_query ($ SQL ); while ($ row = mysql_fetch_assoc ($ result) {$ arr = array (); // you can select the path field or the new conpath field to split the string. // note one point for the explode () function, no matter whether the string to be split contains any character that uses the parameter, at least one array containing an element $ count = count (explode ('-', $ row ['path']) is returned. -1; // str_repeat (), repeat the string mainly for the sake of clear format $ str = str_repeat ('', $ count); echo $ str. $ id. '=> '. $ row ['name']. '

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.