Click on a category to list all products of the current classification and all sub-categories
Above is the classification table, the product table is the cate_id of the related classification table, determine the classification of the product belongs to
Now the effect I want is to click on a category to list all the products of the current classification and all subcategories
Please teach the Great God
Think of the head is broken, recursion? Still is? How do you do that?
------Solution--------------------
Click on the category, so you know the classification number
Querying the database, whatever the parent class number is, is his sub-category.
------Solution--------------------
I don't know about your data size.
Small Business Station, if you get the parent category ID, find all the subcategory IDs, then merge together: 2,5,6,7,8 this
Then to the Product table SQL statement with in keyword to find out, how to use, search it ...
Not sure if you can use the index?
If the amount of data is large, use redundant exchange efficiency
Add a floor field to the classification table, the parent category will write 0, 1 sub-categories will write 1, 2 sub-categories Write 2 ...
Assuming you have 3 levels of classification, then add 3 fields to the product table, Cate,cate1,cate2
Which sub-category the product belongs to, the child from the parent to Level 2 3 fields are filled
Filter according to the incoming Cateid, first find out the category of floor, and then find out all his superior category ID
All that's left is to filter all the obtained IDs as conditions.
The key here is to build a btree index, which is included in the order of Cate to Caten.
The same data volume Method 2 is much faster, but his disadvantage is that the sub-classification when moving to change the product table
------Solution--------------------
This is simple. Just keep inquiring.
The sub-classification is queried by the main classification ID, and the third level is queried from the sub-classification ID, and the fourth level is queried from the third level ID ...
Of course, your server can withstand this kind of toss and go.
Whether you are infinite or not, this is the query. There is no short cut to go.
------Solution--------------------
References:
this is simple. Just keep inquiring.
The sub-classification is queried by the main classification ID, and the third level is queried from the sub-classification ID, and the fourth level is queried from the third level ID ...
Of course, your server can withstand this kind of toss and go.
Whether you are infinite or not, this is the query. There is no short cut to go.
He has a cate_path field ah, no need for this.