Hi im new to codeigniter and im just wondering on how to format the data from a template.
I can format data coming from a row_array result since i dont need to loop it but how can i format data coming from a result_array()??
If i use foreach in controller to format the data i cant loop them in views.
Controller:
Code:
public function loadClients(){
$clientsTotal = $this->client_list_model->getClientTotal();
$activeCount = $this->client_list_model->activeCount();
$inactiveCount = $this->client_list_model->inactiveCount();
$archiveCount = $this->client_list_model->archiveCount();
$data = array(
'project_total' => $clientsTotal['projects_total'],
'pending_total' => $clientsTotal['pending_total'],
'on_going_total' => $clientsTotal['on_going_total'],
'completed_total' => $clientsTotal['completed_total'],
'cancelled_total' => $clientsTotal['cancelled_total'],
'total_price' => number_format($clientsTotal['total'],2),
'paid_total' => number_format($clientsTotal['paid_total'], 2),
'balance_total' => number_format($clientsTotal['balance_total'],2),
'held_price_total' => number_format($clientsTotal['held_price_total'],2),
'client_total' => $clientsTotal['client_total'],
'active_count' => $activeCount['active'],
'inactive_count' => $inactiveCount['inactive'],
'archive_count' => $archiveCount['archive']
);
$data['clients'] = $this->client_list_model->getClients();// I would like to format these results
$data['title'] = 'Client List';
$this->load->view('templates/header');
$this->load->view('pages/activities');
$this->parser->parse('pages/client_list', $data);
$this->load->view('templates/footer');
}
Model:
Code:
function getClients(){
$this->db->select("c.client_id, c.company_name, count(p.project_id) AS projects,
count(CASE WHEN p.project_status = 'Pending' THEN p.project_status END) AS pending,
count(CASE WHEN p.project_status = 'On Going' THEN p.project_status END) AS on_going,
count(CASE WHEN p.project_status = 'Completed' THEN p.project_status END) AS completed,
count(CASE WHEN p.project_status = 'Cancelled'THEN p.project_status END) AS cancelled,
sum(p.total_price) AS total_price, sum(p.paid) AS paid, sum(p.balance) AS balance,
sum(p.held_price) AS held_price, c.client_status");
$this->db->from('clients c');
$this->db->join('projects p', 'c.client_id = p.client_id', 'LEFT');
$this->db->group_by('c.client_id');
$clients = $this->db->get();
return $clients->result_array();
}
View:
Code:
{clients}
<tr>
<td class="left">{client_id}</td>
<td class="left">{company_name}</td>
<td>{projects}</td>
<td>{pending}</td>
<td>{on_going}</td>
<td>{completed}</td>
<td>{cancelled}</td>
<td>{total_price}</td>
<td>{paid}</td>
<td>{balance}</td>
<td>{held_price}</td>
<td>
<span>{client_status}</span>
<a href="client_profile/{client_id}" class="view button">View</a>
</td>
</tr>
{/clients}
I would like to be able to number format or date format the result coming from the model in controllers which is
Code:
$data['clients'] = $this->client_list_model->getClients();