[eluser]Solarpitch[/eluser]
Hey Guys,
I'm a little stuck with the following. I'm calculating a sum of 6 columns in a table, for a specific report. If the report has 2 POS terminals it will return something like...
Till 1: €2156.30
Till 2: €1881.20
The problem is its only printing the last value of the result which is
Till 2: €1881.20. I must need to handle the array differently?
MODEL...
Code:
//see how many till sthe client has reports for on that date
function count_tills($date)
{
$query = $this->client->query('SELECT till FROM golfpro_bar_control_zxread WHERE date = '.$date.' AND path = "real" GROUP BY `till`');
return $query->result();
}
//calculate the total taking for each till that we calculated
function total_till_takings($date, $till)
{
$query = $this->client->query('SELECT SUM(bartotaltrue) AS bt, SUM(foodtotaltrue) AS ft, SUM(specialtotaltrue) AS st,
SUM(golftotaltrue) AS gt, SUM(barsalesaccounttotal) AS at, SUM(barsaleshotelroom) AS rt
FROM golfpro_bar_control_zxread WHERE date = '.$date.' and till = '.$till.' and path = "real"');
$row = $query->row();
$return = "Till ".$till.": ";
$return .= round($row->bt, 2) + round($row->ft, 2) + round($row->st, 2) + round($row->gt, 2) + round($row->at, 2) + round($row->rt, 2);
return $return;
;
}
CONTROLLER...
Code:
function dashboard(){
$this->load->helper('url');
$this->load->model('report_model');
$count_tills = $this->report_model->count_tills('20081209');
foreach($count_tills as $row)
{
$data['total_till_takings'] = $this->report_model->total_till_takings('20081209', $row->till);
}
$data['right_box'] = "right_box/dashboard_view";
$this->load->view('template/page_1', $data);
}
VIEW...
Code:
<?=$total_till_takings?> // WHICH WILL ONLY PRINT OUT "Till 2: €1881.20"