Php unlimited topic category reading implementation code

Source: Internet
Author: User
The following is an example of using Php to classify and read unlimited columns. I hope this article will help you.

The following is an example of using Php to classify and read unlimited columns. I hope this article will help you.

How to Implement the infinitus topic classification idea: Get the auto-increment ID (that is, the parent ID) and then obtain the sub-ID (that is, the uid sub-id) data in the database as follows:
Id: 1 uid: 0 I'm column 1
Id: 2 uid: 1 I'm column 2
Id: 3 uid: 1 I'm a subclass of Column 1

Display result:
I am column 1
I am a subclass of column 1.
I am column 2

Below is the Php code

The Code is as follows:


$ Query = $ this-> db-> query ("SELECT * FROM category ");
$ List = $ query-> result ();
Foreach ($ list as $ v ){
If ($ v-> category_id = 0) {// obtain the parent column (all columns equal to 0 are parent columns)
$ Categoryul = anchor ("home/content/". $ v-> id, $ v-> category_name );
Echo"

    ". $ Categoryul ."
";
$ Listx = $ this-> Listx-> list_id ($ v-> id); // display the specified sub-Column Based on the parent id
Foreach ($ listx as $ vid ){

$ Category = anchor ("home/content/". $ vid-> id, $ vid-> category_name );
Echo"
  • ". $ Category ."
  • ";
    }
    }
    }
    ?>

    ,

    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.