根据我的理解,id是类似版块id,deep是几级版块,ordernum是它的深度(读取时只和前面有联系)。
rootid是做什么的?
回溯的时候,怎样读取?比如现在是3级,要得到它的完整导航bar(读取出它的1和2级)。
rootid是做什么的?
回溯的时候,怎样读取?比如现在是3级,要得到它的完整导航bar(读取出它的1和2级)。
解决方案 »
- 有关php中字符串作数组的操作
- 关于curl_init()老是找不到的问题..帮帮忙谢谢了..。。。。。。。!!!!!!!!!!!!!!!!!!
- 16进制数转化为10进制数,怎么转化啊,这样写不对
- PHP的结果集和ASP的记录集就只是叫法上的不同吗
- fread 远程FTP服务器的文件,只读了一半,请教下怎么解决?
- 怎样读取远程文件的容量大小?
- 求救,谢谢!
- 关于smarttemplate的简单问题
- 100分!如何去掉<input type="hidden" name="PHPSESSID" value="1e3cfa7327459aa2f0c5ce11bc3dd5ed" />
- "Fatal error: Call to a member function on a non-object in "是什么原因造成的?
- 问php的编码规则(关于缩近的问题)
- 请问配置php环境都要注意什么呢,为什么会出现这种情况呢?
================
根据rootid获得上级
id rootiddeepordernum
1000
311 32
432 48
543 56
211 64
简化的算法有待验证2、在基本结构中(id rootiddeepordernum)
id 记录的唯一标识
rootid 记录的顶级记录标识
deep 记录在树中的层次(深度)
ordernum 插值3、数据
id rootiddeepordernum
1000
311 32
412 48
513 56
211 64
表示
1
3
4
5
2
这样的“树”
每个主题就是一个rootid
回复可以是回复主题,也可以是回复其他的回复
<HEAD>
<TITLE> javascript无限制级树形菜单 </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<LINK REL="STYLESHEET" HREF="css/main.css">
<body style="margin:5 0 0 0 ;background-color:lightsteelblue" >
<script>
function isparent(id,url,target,pic,isp)
{
//如果不显示就显示
if(document.all(id+"r").style.display=="none")
{
if(document.all(id+"r").innerText!="")
{
document.all(id+"r").style.display="";
if(isp>0)
{
var img=document.all("a"+id).src;
var imgarray=new Array();
imgarray=img.split("/");
if(imgarray[imgarray.length-1]!="tree_L.gif")
{
document.all("a"+id).src="http://www.pearl-sh.com/php/admin/treeimage/tree_Tminus.gif";
}
document.all("b"+id).src="http://www.pearl-sh.com/php/admin/treeimage/openfld.gif";
}
}
}
//如果显示就不显示
else
{
document.all(id+"r").style.display="none";
if(isp>0)
{
var img=document.all("a"+id).src;
var imgarray=new Array();
imgarray=img.split("/");
if(imgarray[imgarray.length-1]!="tree_L.gif")
{
document.all("a"+id).src="http://www.pearl-sh.com/php/admin/treeimage/tree_Tplus.gif";
}
document.all("b"+id).src="http://www.pearl-sh.com/php/admin/treeimage/clsfld.gif";
}
} ///如果有url
if(url!="")
{
if(target=="")
{
window.open(url);
}
else
{
if(target=="parent")
{
if(confirm("确定了吗"))
{
parent.location.href=url;
}
}else
{
parent.mainFrame.location.href=url;
}
}
}
}
/*******************************************
**********功能:javascript无限制级树形菜单*************
**********作者:peter*************************
**********Email:[email protected]**************
**********发布日期:2004-12-15 ******************
**********下载地址:http://www.lcsww.com/download/index.asp******************
**********请转载时保留版权信息**************
*******************************************/
function additem(pid,textname,nid,url,target,pic,isp)
{//判断是不是存在
// alt 减一
document.all(pid).alt=eval(eval(document.all(pid).alt)-1);
//////////////////////////////父节点alt值
var iso=document.all(pid).iso+document.all(pid).alt+";";//
var thebgcolor="";
var table="";
table=table+"<div id=\""+nid+ "\" titl='"+eval(eval(document.all(pid).titl)+1)+"' alt='"+isp+"' iso='"+iso+"'>";
table=table+"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" >";
table=table+"<tr title=\""+textname+"\" onclick=\"isparent('"+nid+"','"+url+"','"+target+"','"+pic+"','"+isp+"')\" style='cursor:hand;'>";
table=table+"<td>";
//画 | 线条
var k=0;
for(k=0;k<eval(document.all(pid).titl)+1;k++)
{
var str=document.all(pid).iso;
str=str.substring(0,str.length-1);
var strsz=new Array();
strsz=str.split(";");
if(eval(strsz[k])==0)
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_B.gif\" width='19' height='20' >";
}
else
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_I.gif\" >";
}
}
//如果有子,就用+和书本图标表示
if(isp>0)
{
if(eval(document.all(pid).alt)==0)
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_L.gif\" id=\"a"+nid+"\">";
}
else
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_Tplus.gif\" id=\"a"+nid+"\">";
}
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/clsfld.gif\"id=\"b"+nid+"\">";
}
else
//没有子节点直接用图片表示
{
//如果alt>0 判断是不是最后一个节点
if(eval(document.all(pid).alt)>0)
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_T.gif\">";
}
else
{
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/tree_L.gif\">";
}
table=table+"<img src=\"http://www.pearl-sh.com/php/admin/treeimage/"+pic+"\">";
}
table=table+"</td><td>";
table=table+textname;
table=table+"</td>";
table=table+"</tr>";
table=table+"</table>";
table=table+"</div><div id='"+nid+"r' style='display:none;width:"+eval(20*(eval(document.all(pid).titl)+3)+200)+";' ></div>";
document.all(pid+"r").innerHTML=document.all(pid+"r").innerHTML+table;
}</script>
<div id="18"titl="0" style="width:200;" alt="2" iso="1;">
<table border="0" cellpadding="0" cellspacing="0" >
<tr onclick="isparent('18','','mainFrame','link.gif','2')" title="开发语言" style="cursor:hand;">
<td ><!--'判断是不是节点--><img src="http://www.pearl-sh.com/php/admin/treeimage/tree_Tplus.gif" id="a18"><!--'+号--><img src="http://www.pearl-sh.com/php/admin/treeimage/clsfld.gif" id="b18"><!--书本--><!--'结束--></td>
<td >开发语言</td>
</tr>
</table>
</div><div id="18r" style='display:none;width:150'></div>
<div id="26"titl="0" style="width:200;" alt="2" iso="1;">
<table border="0" cellpadding="0" cellspacing="0" >
<tr onclick="isparent('26','','mainFrame','link.gif','2')" title=".NET技术" style="cursor:hand;">
<td ><!--'判断是不是节点--><img src="http://www.pearl-sh.com/php/admin/treeimage/tree_Tplus.gif" id="a26"><!--'+号--><img src="http://www.pearl-sh.com/php/admin/treeimage/clsfld.gif" id="b26"><!--书本--><!--'结束--></td>
<td >.NET技术</td>
</tr>
</table>
</div><div id="26r" style='display:none;width:150'></div>
<div id="1"titl="0" style="width:200;" alt="0" iso="1;">
<table border="0" cellpadding="0" cellspacing="0" >
<tr onclick="isparent('1','itemadd.php','mainFrame','msn.gif','0')" title="栏目管理" style="cursor:hand;">
<td ><!--'判断是不是节点--><img src="http://www.pearl-sh.com/php/admin/treeimage/tree_L.gif"><img src="http://www.pearl-sh.com/php/admin/treeimage/msn.gif"><!--'结束--></td>
<td >栏目管理</td>
</tr>
</table>
</div><div id="1r" style='display:none;width:150'></div>
<script>function itemsettime()
{
try{
var a=(document.all('27').id);
}
catch(e)
{
additem("18","VC/MFC","27","","mainFrame","link.gif","1"); }
try{
var a=(document.all('28').id);
}
catch(e)
{
additem("18","VB","28","","mainFrame","link.gif","0"); }
try{
var a=(document.all('30').id);
}
catch(e)
{
additem("26","C#","30","","mainFrame","link.gif","0"); }
try{
var a=(document.all('31').id);
}
catch(e)
{
additem("26","C# builder","31","","mainFrame","link.gif","0"); }
try{
var a=(document.all('29').id);
}
catch(e)
{
additem("27","基础类","29","","mainFrame","link.gif","0"); }
setTimeout("itemsettime()",100);
}
itemsettime();
</script>
我就要从原理上明白php的实现。真正的rootid应该是它的上一级id吧?
id name parentid根节点的parentid==0
如果保证在数据库中父节点都在子节点的前面(如果按照正常的节点插入操作的就可以满足这一点)
在顺序读取数据库的时候就可以判断parentid,把该条分类加入到父分类下面
中值排序法一般可达15-20层
基本库操作
插入
1、新的顶层节点,执行一次查询、一次插入
2、子节点,执行一次查询、一次修改、一次插入读出
执行一次查询
----------
疑问一:插入的时候,子节点为什么多一次修改?顶节点为什么要查询?
----------
唠叨原话二:
2、插值排序法
除保存接点id和父接点paren_id外还需附加两个插值计算的字段
对“中值排序法”你大概并不陌生,其实他就是这个算法的特例
特点:写入比较复杂、修改、删除接点简单;读出简单
算法概要:
根据预计的规模确定顶层接点的节距
插入子接点时令其插值在相邻接点之间,通常在一侧插入10-20个接点不会出现问题
但是因计算精度的问题,接点值还是会相同的。此时需要调整其后的所有接点的值,通常增加一个节距即可
由此看到,插入接点的算法是比较复杂的。
但是,实用中插入操作是很少的。主要是读出操作。读出时只需对插值排序就可以了
如果在附以表示层次的deep字段,重构“树”就更简单了
-----------
疑问二:父接点paren_id是指本树的最根节点还是子的上一级节点?
疑问三:节距应该是固定在程序中吧?不应该放在数据库中,因为将是一条无用数据。