The word "infinite recursive Classification Query" sounds very advanced. the literal meaning is to query all the categories, "recursion" refers to a function form used in queries-recursive functions.
The word "infinite recursive Classification Query" sounds very advanced. the literal meaning is to query all the categories, recursion refers to a function form used in a query-a recursive function. Classification is the "product" category of a website. generally, a data table is created separately by category, such as document category, product category, and image category.
Some people have doubts: Can I use SQL statements to query all classification records? However, our goal is not only to identify all categories, but more importantly, to "identify by category level", for example:
1. trousers
- Trousers
- Cowboy
2. computers
- Notebook
1. asus
2. Lenovo
- Desktop
3. furniture
- Table
1. dining table
1. square table
2. Round Table
2. desk
- Chair
- Sofa
The above example is the final result we want. However, in the actual classification data table, we cannot classify each level 1, Level 2, and Level 3 ...... The data tables are stored in the pre-configured order, so the directly queried categories are very likely to be messy. The infinite recursive classification query solves this problem. it can sort and indent the categories, just like the example above. The reference functions are as follows:
/**
* Star model training copyright: unlimited recursive Classification Query
* ===================================================== ==================================
* The CMS background management system mainly includes the following:
*
* 1. message management 2. article Management 3. image management
* 4. Category Management 5. navigation management 6. link management
* 7. Template Management 8. user management 9. system settings
*
* Future expansion-> Website product management (for example, products)
* ===================================================== ==================================
* @ File: getSort. php
* @ Author: luchanghong
* @ E-mail: luchanghong@xingmo.com
* @ Date: 2011/6/11
* @ Update:
* @ Copyright: 2002-2011 Beijing xingmo practical training school
**/
/*--------------------------------------------------------------------------/
+ @ Function: infinite recursive Classification Query
+
+ @ Parameter: $ parent_id (parent id), $ table (Category Data table name), $ n (indent)
+
+ @ Return: returns a two-dimensional array that stores classes (id and name) in order)
/--------------------------------------------------------------------------*/
Function getSort ($ parent_id, $ table, $ n =-1)
{
Static $ sort_array = array ();
$ SQL = "SELECT * FROM '{$ table} 'where' parent _ id' =' {$ parent_id }'";
$ Query = mysql_query ($ SQL );
$ N ++;
While ($ res = mysql_fetch_assoc ($ query ))
{
$ Res ['sort _ name'] = str_repeat ('', 4 * $ n). $ res ['sort _ name'];
$ Sort_array [] = $ res;
$ Sort_id = $ res ['sort _ id'];
GetSort ($ sort_id, $ table, $ n );
}
Return $ sort_array;
}
?>