[eluser]Unknown[/eluser]
I'm tryna get the sum of each counted records but have no luck
Code:
function counter() {
for ($i=1; $i<=10; $i++) {
$data['a'] = $this->input->post('i'.$i);
$data['b'] = $this->input->post('answer'.$i);
$ck_answers = $this->Profile_model->ck_answers($data);
$sum = 0;
if(count($ck_answers) > 0):
foreach($ck_answers as $c):
$sum += $c->x;
endforeach;
endif;
}
}
function ck_answers($data)
{
for($i=0; $i<=10; $i++) {
$d = $data['b'];
$item = $data['a'];
$a = $this->input->post('cid');
$query = $this->db->query("SELECT COUNT(*) as x FROM table where colA = $a AND colB = $item AND colC = '$d'");
return $query->result();
}
}
When I tried to echo it echoes the row not the sum. Please help