PHP MySQL method to implement unlimited classification columns, _PHP tutorial

WBOY
Release: 2016-07-12 09:02:39
Original
1059 people have browsed it

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

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template