【发布时间】:2023-04-01 01:48:02
【问题描述】:
public function left_team_count2()
{
$right = $this->register->left_team();
echo '<table border="1">
<tr>
<th>name</th>
<th>id</th>
</tr>
<tbody>';
$i = 1; foreach($right as $row)
{
echo '<tr>
<td>'.$i.'</td>
<td>'.$row['name'].'</td>
<td>'.$row['user_id'].'</td>';
while(!empty($row['child'])){
foreach($row['child'] as $row)
{
echo '<tr>
<td>'.$i.'</td>
<td>'.$row['name'].'</td>
<td>'.$row['user_id'].'</td>
</tr>
';
while(!empty($row['child'])){
foreach($row['child'] as $row)
{
echo '<tr>
<td>'.$i.'</td>
<td>'.$row['name'].'</td>
<td>'.$row['user_id'].'</td>
</tr>';
$i++; }
}
$i++;}
}
echo '</tr>';
$i++; }
echo '</tbody>
</table>';
echo '<pre>';
print_r($right);
这是模型/功能
function left_team()
{
$result = $this->db->select('user_id,name,time,activation,status')->from('login')->where('side','Left')->where(array('sponser'=>$this->session->userdata('username')))->get()->result();
$employee = array();
foreach($result as $data){
$emp = array();
$emp['user_id']=$data->user_id;
$emp['name']=$data->name;
$emp['time']=$data->time;
$emp['activation']=$data->activation;
$emp['status']=$data->status;
$emp[] = $data->user_id;
$emp['child'] = $this->left_count($emp);
array_push($employee,$emp);
}
return $employee;
}
function left_count($emp)
{
$this->db->where_in('sponser',$emp);
$q = $this->db->get('login');
$tree = $q->result();
$employee = array();
foreach($tree as $data){
$emp = array();
$emp['user_id']=$data->user_id;
$emp['name']=$data->name;
$emp['time']=$data->time;
$emp['activation']=$data->activation;
$emp['status']=$data->status;
$emp[] = $data->user_id;
$emp['child'] = $this->right_count($emp);
array_push($employee,$emp);
}
return $employee;
}
我们正在研究二叉树计划结构,数据在 foreach 循环中获取得非常好,但是当我们试图在表中显示数据时它无法正常工作。它只显示总数据的一半,有时甚至不显示一半的数据。帮我解决这个问题,提前谢谢......
【问题讨论】:
标签: php codeigniter