谢谢,现在已经得到缩进的结构了。像这样,我再想怎么形成树状呢。 directeur general directeurs des projets/realisations chef de projets Adjoint chef de projet Directeur commercial customer manager tendence manager Engineering Responsable offre techniques/ Ingenieurs offre Responsable mecanique Responsable electrique Responsable procedes Responsable quarantie engineering Qualite projet Projet management office(PMO) planification generale Sourcing Acheteur projets Expediting Achat famille Logistique Travaux exterieures Site manager commissioning manager manufacturing Production Esais Planification production Investissement travaux neufs Finance Controle de gestion RH Formation Recrutement ressources Services Directeur de offres/ Ingenieurs chiffrage Directeur commercial/ Service commercial Directeur de realisation Chef de projet Planificateur Achat Chantier Qualite
`id` int(3) NOT NULL auto_increment,
`name` varchar(50) NOT NULL default '',
`parentID` varchar(50) NOT NULL default '',
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM COMMENT='树型' AUTO_INCREMENT=37 ;
2. graphviz
3. flash
4. xml急!!!
id
companyName
parentid
这样的表结构就可以实现二叉树的保存。
至于遍历,我是取出一个父节点的所有子节点保存到缓存文件,省去以后的麻烦,至于保存我也啥好想法,我是保存数组中,类似这样的数组array('id'=>$id,'name'=>$companyName,'children'=>array($child1id,$child2id))以后再取的时候就可以很方便的取出一个父节点的所有子节点的,至于怎么判断一个节点是否是叶子节点,只需判断它所在数组的children元素是否为空就可以了
父ID
子ID用php的话用数组吧
谢谢你的回复,我觉得你的方法还挺实用。可是这里的结构不是二叉树,一个parent下有多个children。 这样的情况,该如何解决?
左子树表示children, 右子树表示sibling
directeur general
directeurs des projets/realisations
chef de projets
Adjoint chef de projet
Directeur commercial
customer manager
tendence manager
Engineering
Responsable offre techniques/ Ingenieurs offre
Responsable mecanique
Responsable electrique
Responsable procedes
Responsable quarantie engineering
Qualite projet
Projet management office(PMO) planification generale
Sourcing
Acheteur projets
Expediting
Achat famille
Logistique
Travaux exterieures
Site manager
commissioning manager
manufacturing
Production
Esais
Planification production
Investissement travaux neufs
Finance
Controle de gestion
RH
Formation
Recrutement ressources
Services
Directeur de offres/ Ingenieurs chiffrage
Directeur commercial/ Service commercial
Directeur de realisation
Chef de projet
Planificateur
Achat
Chantier
Qualite
$result[0] = array('id'=>1,'pid'=>0,'name'=>'公司1',);
$result[1] = array('id'=>2,'pid'=>0,'name'=>'公司2');
$result[2] = array('id'=>3,'pid'=>2,'name'=>'公司2的子公司1');
$result[3] = array('id'=>4,'pid'=>1,'name'=>'公司1的子公司1');
$result[4] = array('id'=>5,'pid'=>2,'name'=>'公司2的子公司2');
$result[5] = array('id'=>6,'pid'=>3,'name'=>'公司2的子公司1的子公司1');
$result[6] = array('id'=>7,'pid'=>3,'name'=>'公司2的子公司1的子公司2');
//简易类
class tree
{
function tree($rs,$idName,$pidName,$nodeName)
{
$this->idName = $idName;
$this->nodeName = $nodeName;
$tree = array();
foreach((array)$rs as $k=>$v)
{
$tree[$v[$pidName]][] = $v;
} $this->treeArray = $tree;
}
function showTree($root,$deep)
{
if( $this->treeArray[$root] )
{
foreach($this->treeArray[$root] as $k=>$v)
{
$t = $v[$this->idName];
$str = str_repeat(" ",$deep*4)."|-".str_repeat("-",$deep);
$html .="{$str}{$v[$this->nodeName]}<br/>";
if($this->treeArray[$t] )
{
$gx = $deep + 1;
$html .= $this->showTree( $t,$gx );
}
}
}
return $html;
}
}
$tree = new tree($result,'id','pid','name');
echo $tree->showTree(0,0);
http://www.graphviz.org/
东西是不错,不过在PHP里没办法用
不知道什么实现?