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);
this is model/function
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;
}
We are working on a binary tree plan structure, the data is fetching very well in the foreach loop but when we are trying to show the data in the table it not working properly. It's showing only half of the total data or sometimes not even the half of the data. Help me to get rid of the problem, thank you in advance.....