Database-PHP first-level column reads Articles under Level 3 columns?

Source: Internet
Author: User
The website has three levels of columns: one topic type table and one article table topic type: idpid (id and parent layer id) Article type: idtyid (id and topic id) example: {code ...} how can I display all articles in football in sports ?? How should I read it? This website is divided into three levels: a column type table and an article table.

Topic type: id pid (id and parent layer id)
Article type: id tyid (id and topic id)

For example:

Sports id = 1 pid = 0 ball game id = 10 pid = 1 football id = 20 pid = 10 football article id = casual tyid = 20

How can I display all articles in football in sports ?? How should I read it?
I am a beginner in php and mysql. Hope you can give me some advice! Please do not randomly add join SQL concatenation or recursive reading! Thank you!

Reply content:

The website has three levels of columns: one column type table and one article table.

Topic type: id pid (id and parent layer id)
Article type: id tyid (id and topic id)

For example:

Sports id = 1 pid = 0 ball game id = 10 pid = 1 football id = 20 pid = 10 football article id = casual tyid = 20

How can I display all articles in football in sports ?? How should I read it?
I am a beginner in php and mysql. Hope you can give me some advice! Please do not randomly add join SQL concatenation or recursive reading! Thank you!

First, write a recursive function to query the child directory id, and then query the article with the directory id as the query condition.

There are many ways to read data. I will give you a more convenient query method, but you need to modify the table structure.

Add a level and top_id

select * from table where top_id = 1 and level = 3

In this way, all the three-level categories are queried and the corresponding articles are queried by category.

The advantage is that two more fields need to be maintained in the background management (of course, the specific fields need to be processed according to your business logic)

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.