Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[已解决] 无限级分类程序

[复制链接]
tkggypmn 发表于 2011-9-9 21:44:40 | 显示全部楼层 |阅读模式
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 );
}
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-11-15 01:20 , Processed in 0.031025 second(s), 4 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表