Home>

Database structure:

create table if not exists `city` (
 `id` int (11) not null auto_increment, `name` varchar (30) character set utf8 collate utf8_unicode_ci not null default" 0 ", `parentid` int (11) not null default" 0 "
 primary key (`id`)
) engine=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);
php
  • Previous JSP + EXt20 method to achieve paging
  • Next asp + jsp + JavaScript dynamically add data rows