php 遍历树,子节点可以有多个父节点,请诸位大神指点

WBOY
Release: 2016-06-13 12:37:44
Original
1094 people have browsed it

php 遍历树,子节点可以有多个父节点,请各位大神指点

本帖最后由 asmd1234567 于 2013-09-12 11:56:42 编辑 我希望展示父子关系,一个父节点可以有多个子节点,一个子节点可以有多个父节点,由于一直运行不通过,也不知道自己写的函数是不是正确的,不好意思啊
 $result = array(); /*Parse error: syntax error, unexpected '=', expecting ',' or ';' */<br />
/*我本来希望这个是个全局的数组,但是上网查了一下,发现现在不可以了,不知道各位大神有没有什么好的方法,小弟在此谢过啦*/<br />
$result[0] = mysql_query("select cID,number,isbasicpart from relationship  where pID='{$id}'");/*cID为子节点号,isbasicpart为是否为叶节点,number为父子间的数量*/<br />
<br />
<br />
echo "<table cellpadding='0' cellspacing='0' border='0'>"; <br />
echo "<tr> <td> {$id}";<br />
$i=0;<br />
<br />
<br />
 <br />
	function buildtree($i){<br />
<br />
	 while($row = mysql_fetch_array($result[$i])){ <br />
if($row['isbasicpart']==1)<br />
  echo "<td>'--'<td>{$row['cID']}<td>'('<td> {$row['number']}<td>')'</tr>";<br />
else  { echo "<td>'--'<td>{$row['cID']}<td>'('<td> {$row['number']}<td>')'";<br />
           <br />
$i=$i+1;<br />
$sql="select cID,number,isbasicpart from relationship  where pID='{$row['cID']}'"; <br />
$result[$i]=mysql_query($sql);<br />
<br />
 buildtree($i);<br />
<br />
<br />
<br />
}<br />
<br />
}<br />
 echo '</table>';<br />
<br />
}<br />
 buildtree(0);<br />
<br />
}
Copy after login
php 遍历 多个父节点
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template