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