我在树查询中有多个值。我希望得到数组的所有3个值并在表格中显示结果..不幸的是我只有第3个记录,我已经甚至在第二个数组中回显表,但什么也没有显示..有什么方法可以做到吗?
$sql = mysql_query("select userid from dept_user where lead_id=61");
while($res = mysql_fetch_array($sql)){
// $user = $res['userid'];
$a = $res['userid'];
if ($a !== 0){
echo "1st: " . $a;
echo "<br/>";
$s = mysql_query("select userid from dept_user where lead_id=$a");
while($res = mysql_fetch_array($sql)) {
$q = $res['userid'];
echo "<br/>";
if($q !==0) {
echo "Second: " . $q;
echo "<br/>";
$f = mysql_query("select userid from dept_user where lead_id=$q");
while($res = mysql_fetch_array($f)) {
$u = $res['userid'];
$n = mysql_query("Select user.firstname, user.lastname, department.dept_name, job_title.title, role.rolename, user.userid From user Inner Join dept_user On user.userid = dept_user.userid Inner Join department On department.dept_id = dept_user.dept_id Inner Join job_title On job_title.title_id = user.titleid Inner Join role On role.roleid = user.roleid Where user.userid = $u ");
echo "<table border='1'>
<tr>
<th>id</th>
<th>first name</th>
<th>last name</th>
<th>dept name</th>
<th>title</th>
<th>rolename</th>
</tr>";
while($row = mysql_fetch_array($n)) {
echo "<tr>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['dept_name'] . "</td>";
echo "<td>" . $row['title'] . "</td>";
echo "<td>" . $row['rolename'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
}
}
}
}
答案 0 :(得分:0)
尝试在$ res到$ res1和$ res2
的第二个和第三个循环中重命名变量