PHP Simple implementation of infinite class classification method, PHP infinite class classification _php tutorial

Source: Internet
Author: User
Tags php regular expression

PHP Simple implementation of infinite class classification method, PHP infinite class classification


In this paper, we describe the simple implementation of an infinite class of PHP methods. Share to everyone for your reference, as follows:

Database structure:

CREATE TABLE IF not EXISTS ' city ' (' id ' int (one) not NULL auto_increment, ' name ' varchar () character Set UTF8 collate UT F8_unicode_ci NOT NULL default ' 0 ', ' parentid ' int (one) not null default ' 0 ' PRIMARY KEY (' id ')) engine=myisam default CHAR Set=latin1 auto_increment=7;

PHP Files:

$DB =new db ($Config [' Host '], $Config [' User '], $Config [' Password '], $Config [' Port '], $Config [' db '], $Config [' CharSet '] ); function findcity ($table, $id =0, $level =1) {  global $db;  $FINDSQL = "Select Id,name,parentid from $table the Where parentid={$id} ORDER by id";  $findResult = $db->getarray ($FINDSQL);  $num = $db->numrows;  $LOGOSTR = "|";  for ($i =0; $i < $level; $i + +) {  $logoStr. = "--";  }   if ($num!=0) {for   ($j =0; $j < $num; $j + +) {     echo{$LOGOSTR} {$findResult [$j][name]} ";        Findcity ($table, $findResult [$j] [' ID '], $level + 1);}}  Findcity (city);

More about PHP related content readers can view this site topic: "PHP array" operation Skills Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Math Skills Summary, "PHP Regular Expression Usage summary", "PHP Operations and Operator Usage Summary", "PHP string Usage Summary" and "PHP common database Operation Skills Summary"

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1127913.html www.bkjia.com true http://www.bkjia.com/PHPjc/1127913.html techarticle PHP Simple implementation of infinite-level classification method, PHP infinite class Classification This article describes the simple implementation of PHP infinite class classification method. Share to everyone for your reference, as follows: Database ...

  • 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.