• 1000
Моя попытка:
контроллер:
public function overview(){
$data['main_view'] = 'projects/overview';
$data['data']=$this->project_model->get_data();
$this->load->view('layouts/main' , $data);
}
вид:
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>Project Name</th>
<th>Client Name</th>
<th>Due</th>
<th>Pending Tasks</th>
<th>In progress Tasks</th>
<th>Completed</th>
</tr>
</thead>
<tbody>
<?php foreach ($data as $row): ?>
<tr>
<td><?php echo $row->project_id ?></td>
<td><?php echo $row->project_name ?></td>
<td><?php echo $row->name ?></td>
<td><?php echo $row->due_date ?></td>
<td><?php echo $row->pending_tasks ?></td>
<td><?php echo $row->in_progress ?></td>
<td><?php echo $row->completed_tasks ?></td>
</tr>
<?php endforeach;?>
</tbody>
</table>
Модель:
public function get_data(){
$status = array(
'status' =>'Completed' ,
'status' =>'Pending',
'status' =>'In progress'
);
$this->db->select("projects.*,Count('tasks.*') as pending_tasks,Count('tasks.*') as completed_tasks,Count('tasks.*') as in_progress,clients.name");
$this->db->join('tasks','tasks.project_id=projects.project_id');
$this->db->join('clients','clients.id=projects.client_id');
$this->db->where_IN(['tasks.status'=> $status]);
$this->db->group_by('tasks.project_id');
$q =$this->db->get('projects');
return $q->result();
}
Результат, который я получаю, общее количество задач с соответствующими статусами в каждом столбце. его не разделить