How to implement unlimited classification columns with PHP MySQL,
This article describes the method of implementing unlimited classification columns with PHP MySQL. Share it with everyone for your reference, the details are as follows:
A very simple, clear and simple unlimited classification example with indentation effect. You only need to query the data table once and then recursively traverse the result set. If you want to implement column indentation display in PHP, you can refer to it.
$sql = 'select * from cat order by cat_id desc';
$list = $db->getAll($sql);
$list = getLevelCat($list);
function getLevelCat($catlist, $parent_id='0', $html=' ', $level='0'){
$arr = array();
foreach($catlist as $val){
if($val['parent_id']==$parent_id){
$val['html'] = str_repeat($html,$level);
$val['level'] = $level;
$arr[] = $val;
$arr = array_merge($arr, getLevelCat($catlist, $val['cat_id'], $html, $level+1));
}
}
return $arr;
}
Copy after login
Implementation renderings:
Just a few lines of code, clearer and easier to use.
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- php mysql implements unlimited classification
- Jquery Ajax PHP MySQL implements classification list management (Part 2)
- Jquery Ajax PHP MySQL implements classification list management (Part 1)
- Summary of methods to implement unlimited classification in PHP Mysql
- Detailed explanation of examples of php mysql to implement unlimited classification
- Methods to implement unlimited classification in php mysql database
- Examples of two methods of database design with PHP Mysql tree structure (infinite classification)
- Infinite level classification examples of php mysql without recursion (non-recursive)
- php mysql Realize infinite levels of classification | Tree display classification relationships
http://www.bkjia.com/PHPjc/1084557.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1084557.htmlTechArticleHow PHP MySQL implements unlimited classification columns. This article describes the method of PHP MySQL implementing unlimited classification columns. Share it with everyone for your reference, the details are as follows: A very simple...