我有一个地区表,如下:
id ,parentid,name
1 0 中国
2 1 上海
3 1 江苏
4 2 浦东
5 2 虹口
6 4 张江
7 4 金桥
现在想统计隶属下海的地区下共有多少子类,怎么写这个递归程序,我用下面的方法取得的结果不对function getdistricts($distid = 0, $distids) {
global $_SGLOBAL; if (empty ($distids)) $distids = $distid;
$sql = "select * from " . tname('district') . " where reid=$distid";
$query = $_SGLOBAL['db']->query($sql);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$distids = $distids . "," . $value['id'];
echo $distids."<br>";
return getdistricts($value['id'], $distids);
}
return $distids;
}
怎么递归?
id ,parentid,name
1 0 中国
2 1 上海
3 1 江苏
4 2 浦东
5 2 虹口
6 4 张江
7 4 金桥
现在想统计隶属下海的地区下共有多少子类,怎么写这个递归程序,我用下面的方法取得的结果不对function getdistricts($distid = 0, $distids) {
global $_SGLOBAL; if (empty ($distids)) $distids = $distid;
$sql = "select * from " . tname('district') . " where reid=$distid";
$query = $_SGLOBAL['db']->query($sql);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$distids = $distids . "," . $value['id'];
echo $distids."<br>";
return getdistricts($value['id'], $distids);
}
return $distids;
}
怎么递归?
global $_SGLOBAL; if (empty ($distids)) $distids = $distid;
$sql = "select * from district where parentid=$distid";
$query = $_SGLOBAL['db']->query($sql);
while ($value = $_SGLOBAL['db']->fetch_array($query)) {
$distids = $distids . "," . $value['id'];
echo $distids."<br>";
return getdistricts($value['id'], $distids);
}
return $distids;
}