Php+mysql method of realizing non-limit classification column _php skill

Source: Internet
Author: User

This paper illustrates the method of Php+mysql to realize the column without limit classification. Share to everyone for your reference, specific as follows:

A very simple and simple example of No limit classification, with indentation effect, just query the data table, and then recursively traverse the result set, you can, in PHP to achieve column indentation display can refer to.

$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;
}

To implement the effect diagram:

A few lines of code, more clear, but also more useful.

I hope this article will help you with the PHP program design.

Related Article

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.