我有一个名为tbl_tasks的任务表。这有数据,也有parent_id。
表的结构是
t_id, project_id, title , parent_id
1 1 Task1 0
data 2 1 Sub Task1 1
3 1 Child Sub task1 2
此表中还有另一个名为tbl_sharedtasks的表,其中包含共享任务的数据。
表的结构是
project_id,user_id,t_id,createdby
data 1 1 3 3
当我想为我的共享任务显示Ancestors树视图时,这只检测一条记录但不检测其父记录。其中1和2也应该是因为共享t_id 3有pareint_id 2而2有pareint_id 1
这是我的代码
$qry="SELECT sh.task_id,tsk.* FROM tbl_sharedtasks sh,tbl_tasks tsk where sh.project_id=1 and sh.user_id=1 and tsk.t_id=sh.task_id";
$result=mysql_query($qry);
$arrayCategories2 = array();
while($row = mysql_fetch_assoc($result)){
$arrayCategories2[$row['t_id']] = array("parent_id" => $row['parent_id'], "title" =>
$row['title'],"task_id" => $row['t_id']);
}
?>
<?php
if(mysql_num_rows($result)!=0)
{
?>
<?php
createTreeView($arrayCategories2, 0); ?>
<?php
}?>
这是我的CreateTreeView Funciton
function createTreeView($array, $currentParent, $currLevel = 0, $prevLevel = -1)
{
$id=0;
foreach ($array as $categoryId => $category)
{
$id++;
if ($currentParent == $category['parent_id'])
{
if ($currLevel > $prevLevel) echo " <ul style='list-style:none; cursor:pointer' id='folder21'> ";
if ($currLevel == $prevLevel) echo " </li> ";
echo "<li > <span class='file'> ";?><a onClick="selecttaskval('<?php echo $category['task_id'];?>','<?php echo $category['title'];?>');"><?php echo $category['title'];?></a> </span>
<?php
if ($currLevel > $prevLevel) { $prevLevel = $currLevel; }
$currLevel++;
createTreeView ($array, $categoryId, $currLevel, $prevLevel);
$currLevel--;
}
}
if ($currLevel == $prevLevel) echo " </li> </ul> ";
}
只有当我从tbl_tasks中选择记录时才能正常工作,但是当我想从共享表中检测到记录时,这种工作正常。 请帮助谢谢