This article describes the simple implementation of PHP to achieve the infinite level of classification methods. Share to everyone for your reference, specific as follows:
Database structure:
CREATE TABLE IF not EXISTS ' city ' (
' id ' int (one) not NULL auto_increment,
' name ' varchar () Character Set UTF8 Co Llate utf8_unicode_ci NOT null default ' 0 ',
' parentid ' int (one) not null default ' 0 '
PRIMARY KEY (' id ')
engin E=myisam DEFAULT charset=latin1 auto_increment=7;
PHP File:
$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 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 "<option value={$findResult [$j] [' id ']}>{$logoStr}{$ findresult[$j][name]}</option> ";
Findcity ($table, $findResult [$j] [' ID '], $level + 1);
}}
Findcity (city);
More about PHP Interested readers can view the site topics: "PHP array" Operation tips Daquan, "PHP Sorting algorithm Summary", "PHP common traversal algorithm and skills summary", "PHP Data structure and algorithm tutorial", "PHP Programming Algorithm Summary", " PHP Mathematical Calculation Skills Summary, "PHP Regular Expression Usage summary", "PHP operation and operator Usage Summary", "PHP string (String) Usage summary" and "PHP common database Operation skill Summary"
I hope this article will help you with the PHP program design.