Welcome Guest, Not a member yet? Register   Sign In
Select Count(*) problem
#3

[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">
    &lt;?php foreach ($records as $row) {
        echo '<tr><td>' . $row->value1 . '</td><td>' . $row->valuetotal . '</td></tr>';
    }
    ?&gt;
</table>

Note: Code is untested, you may need to modify it to suit. But that's the basic theory you need.


Messages In This Thread
Select Count(*) problem - by El Forum - 04-24-2011, 06:02 AM
Select Count(*) problem - by El Forum - 04-24-2011, 09:20 AM
Select Count(*) problem - by El Forum - 04-25-2011, 08:04 PM
Select Count(*) problem - by El Forum - 04-26-2011, 03:16 AM
Select Count(*) problem - by El Forum - 06-15-2011, 07:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB