function mainpfl($pid, $depth, $v, $table) {
$result = mysql_query ( "select cat_id,parent_id,cat_name from " . $GLOBALS [prefix] . $table . " where parent_id=0 AND is_show='1' order by cat_id desc" );
$numrows = mysql_num_rows ( $result );
if ($v == 1) {
if ($pid == "0") {
echo "<option selected='selected' value='0'>顶级分类</option>";
} else {
echo "<option value='0'>顶级分类</option>";
}
} else {
echo "<option value=''>请选择...</option>";
}
for($rows = 0; $rows < $numrows; $rows ++) {
$myrow = mysql_fetch_array ( $result );
if ($pid == $myrow [cat_id]) {
echo "<option selected='selected' value=" . $myrow [cat_id] . "> " . $myrow ["cat_name"] . "</option>";
} else {
echo "<option value=" . $myrow [cat_id] . "> " . $myrow ["cat_name"] . "</option>";
}
$depth ++;
subpfl ( $pid, $myrow ["cat_id"], $depth, $table );
}
}
//定义子级分类
function subpfl($pid, $cid, $depth, $table) {
$result = mysql_query ( "select cat_id,parent_id,cat_name from " . $GLOBALS [prefix] . $table . " where parent_id=$cid AND is_show='1' order by cat_id desc" );
$numrows = mysql_num_rows ( $result );
for($rows = 0; $rows < $numrows; $rows ++) {
$myrow = mysql_fetch_array ( $result );
for($i = 0; $i < $depth; $i ++) {
$str = " ";
$str .= " ";
}
if ($pid == $myrow [cat_id]) {
echo "<option selected='selected' value=" . $myrow [cat_id] . ">" . $str . "" . $myrow ["cat_name"] . "</option>";
} else {
echo "<option value=" . $myrow [cat_id] . ">" . $str . "" . $myrow ["cat_name"] . "</option>";
}
$depth ++;
subpfl ( $pid, $myrow ["cat_id"], $depth, $table );
}
} |