[eluser]Aken[/eluser]
The
count_all_results() function is designed to be used with other active record database methods. It is an alternate to methods such as
get(). It can not be used on a result set returned from other DB methods. You will want to use the COUNT() function as suggested by Ngulo.
Model:
Code:
$q = $this->db->select('value1, COUNT(1) valuetotal')->group_by('value1')->get(TBL_1);
$result = $q->result();
$numrows = $q->num_rows();
if ( ! $result || $numrows < 0) {
echo 'Error'; return;
}
else if ($numrows === 0) {
return;
}
else {
return $result;
}
View:
Code:
<table border="1px">
<?php foreach ($records as $row) {
echo '<tr><td>' . $row->value1 . '</td><td>' . $row->valuetotal . '</td></tr>';
}
?>
</table>
Note: Code is untested, you may need to modify it to suit. But that's the basic theory you need.