Php Infinitus _ PHP Tutorial

Source: Internet
Author: User
Php Infinitus classification. Php Infinitus classification is often used. I have used it well before, so I have not studied it carefully. today, due to the needs of the project, A php Infinitus classification is required temporarily.

Php Infinitus classification is often used. I have used it well before, so I have not studied it carefully. today, due to the needs of the project, you need to temporarily create a php Infinitus classification, and then make a simple one. The record is as follows. if you need it, you can check it out.

Data table structure

Create table if not exists 'Category '('id' int (5) not null AUTO_INCREMENT COMMENT 'unique auto-incrementing ID', 'pid' int (5) not null default '0' COMMENT 'parent ID', 'sort 'int (2) not null default '0' comment' sort number', 'name' varchar (30) default null comment 'name', primary key ('id') ENGINE = MyISAM default charset = utf8 COMMENT = 'infinitus classification table' AUTO_INCREMENT = 1;

Data

Insert into 'category '('id', 'pid', 'sort ', 'name') VALUES (1, 0, 1, 'php'), (2, 0, 2, 'database'), (3, 0, 3, 'javascript '), (4, 1, 1, 'framework template'), (5, 1, 2, 'function summary'), (6, 2, 1, 'mysql'), (7, 4, 1, 'framework'), (8, 4, 2, 'Template'), (9, 8, 1, 'smarty '), (10, 7, 2, 'thinkphp'), (11, 10, 1, 'thinkphp Times'), (12, 10, 2, 'thinkphp templates'), (13, 12, 3, 'Template knowledge summary'), (14, 12, 2, 'template video example'), (15, 11, 1, 'Model Times ');

Function implementation code

function tree(&$list,$pid=0,$level=0,$html='--'){    static $tree=array();    foreach($list as $v){        if($v['pid']==$pid){            $v['level']=$level;            $v['html']=str_repeat($html,$level);            $tree[]=$v;            tree($list,$v['id'],$level+1,$html);        }     }    return $tree;}

The first parameter $ list of the tree function above is the result set obtained from a two-dimensional array in the preceding table. Note that order by sort asc must be added to the SQL statement used to obtain the result set from the database. Otherwise, the sort field cannot be used for sorting.

Articles you may be interested in
  • Php clears (deletes) the files in the specified directory, and does not delete the directory folder.
  • Php gets the method of each month in a certain period of time, and returns an array composed of these months
  • Php obtains the start and end timestamps of today, yesterday, last week, and this month.
  • Why PHP setcookie is invalid
  • Php summarizes the N methods used to obtain the timestamp of today, tomorrow, and yesterday
  • PHP compresses html webpage code (clear spaces, line breaks, tabs, comment tags)
  • Insert and Update statements used by PHP beginners
  • How to write array variables to files in PHP

Limit php Infinitus classification is often used. I have used it well before, so I have not studied it carefully. today, due to the needs of the project, I need to do a temporary task...

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.