写了文章一个无限分类程序 select * from tablename parentid = "一个值" 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写递归函数 大概如下应该再添加一个字段:isleaf :是否是叶子节点/function recursion($parentid){$sql=select id,parentid,name from tbl where parentid=$parentid$query = $db->query($sql);while($row=$query->fetchRow(DB_FETCHMODE_ASSOC)){ if($row["isleaf"]==1){//是叶子节点 其他操作 }else{ recursion($row["id"]); }}} 我明白了啊!不过这样好似是一个“关系型”的迭代!设一个Root id:0其它的下属parent=0给一个例子:Root(0) |+Item1(1) | |-Element1(2) |-Item2(3) |-Element2(4)---------------------------id parentid name 0 0 Root1 0 Item12 1 Element13 0 Item24 0 Element2---------------------------Select * from Options where parentid = "0";返回结果保存到Root的存储区里以Parentid做递归的参数递归(参见一下文件夹的遍历)国外有一个Blog软件中好像就用这种方法做的Post记录,到底是哪个,忘啦!有时间找出来再说。呵呵,这个很有前途啊! 哦,想起来了,好像一个叫UltraTree的东西同样能完成这中功能。我有代码,不知道怎么给你啊 http://www5.uuzone.com/uu/janlon/blog/5554.htm 已调试通过了。function listTree($parentid = 0){ include "config.inc.php"; $sql = "select * from $sort_table where parentid = $parentid"; $res = mysql_query($sql); $num++; while($arr = mysql_fetch_array($res)) { // 输出当前结点信息 echo "<option value=\"$arr[sortid]\" "; if($arr[sortid]==$default)echo "selected"; echo ">" .str_repeat( " ", $num-1 ). "-" . $arr['name'] . ""; echo "</option>\n"; //查询该结点的子节点 listTree($arr['sortid']); }} 为什么都建议不学架构 vertrigoSerV 2.14中为什么无法执行setInterval呢 新浪微薄,Twitter等短URL地址生成技术 请教discuz模板类循环嵌套问题 准备扛着PHP搞电子政务了,大家给点意见 高手指点,老师请进! linu下phpmailer发送邮件的问题 谁有好的apache+php+mysql的自动安装程序 是否知道:php朋友请看页面超时,怎么做…… file_exists($fn) || touch($fn); 请问,如何在点击媒体文件时提示下载,而不是直接播放? 这个技术有人给我搞定,我高分送上.绝不食方
$sql=select id,parentid,name from tbl where parentid=$parentid
$query = $db->query($sql);
while($row=$query->fetchRow(DB_FETCHMODE_ASSOC)){
if($row["isleaf"]==1){//是叶子节点
其他操作
}else{
recursion($row["id"]);
}
}}
不过这样好似是一个“关系型”的迭代!
设一个Root id:0
其它的下属parent=0
给一个例子:
Root(0)
|+Item1(1)
| |-Element1(2)
|-Item2(3)
|-Element2(4)
---------------------------
id parentid name
0 0 Root
1 0 Item1
2 1 Element1
3 0 Item2
4 0 Element2
---------------------------
Select * from Options where parentid = "0";返回结果保存到Root的存储区里
以Parentid做递归的参数递归(参见一下文件夹的遍历)
国外有一个Blog软件中好像就用这种方法做的Post记录,到底是哪个,忘啦!
有时间找出来再说。呵呵,这个很有前途啊!
function listTree($parentid = 0)
{
include "config.inc.php";
$sql = "select * from $sort_table where parentid = $parentid";
$res = mysql_query($sql);
$num++;
while($arr = mysql_fetch_array($res))
{
// 输出当前结点信息
echo "<option value=\"$arr[sortid]\" ";
if($arr[sortid]==$default)echo "selected";
echo ">" .str_repeat( " ", $num-1 ). "-" . $arr['name'] . "";
echo "</option>\n";
//查询该结点的子节点
listTree($arr['sortid']);
}
}