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

[eluser]jacobson[/eluser]
Hello I have a problem with "passing" the number of records (count(*))

I have a model:
Code:
$this->db->select('value1');
        $this->db->group_by('value1');
        $q = $this->db->get(TBL_1);
        $result = $q->result();
        if(!$result || ($q->num_rows() < 0)){
            echo "Error";
            return;
        }
        if($q->num_rows() == 0){
            return;
        }
        return $result;

My controller passes the informations to the view which looks like:

Code:
<table border="1px">
    &lt;?php
    foreach($records as $row) {
        echo "<tr><td>" . $row->value1 . "</td><td>" .  $this->db->count_results($row->value1) . "</td></tr>";
    }
    ?&gt;
    </table>

In the place where I "try" to count results in the view i want to have the number of records where the field is equal to "value1".
I'm quite sure that I'm doing something wrong and that I should cound those values in my model. But my controller :
Code:
$this->load->model('data_selection_model');
        $data['records'] = $this->data_selection_model->display_data_number();
assigns to $records the value of $result from the model which stores the value1. I tried at first making in model select ('value1', 'count(*)') but in the view there appears the problem. i can do $row->value1 but I cant do $row->count(*).

I hope someone could help me with this problem Smile


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