views:

28

answers:

1

Alright, Im trying to count all the rows where "Membership_Status" = Active. The result I get right now is "Array" instead of a number.

Here is my model

class Report_model extends Model
{
 function count_members()
 {
  $query = $this->db->get_where('Membership', array('Membership_Status' => 'Active'));
  return $query->num_rows();
 }


}

Here is my controller


class Report extends Controller {

 function YTD_report()
 {

     $data['main_content'] = 'report_membership_view';
        $this->load->view('includes/template', $data);


 }

}

Here is my view


report_model->count_members();
echo $total;

?>

My result is Array, where according to the db info, it should be 4.

What can I do/change to get it to display the proper number?

thanks

+1  A: 

the $data array your passing to the view will create one variable for each key to be used by view...

So your controler once the model is loaded, you should do:

$data['total'] = $this->Report_model->count_members();

Then in the view you can use the $total variable like this:

<?php echo $total; ?>
t00ny
Thank you very much, that worked nicely!
JonYork
Glad I could help... I don't use codeigniter myself so I wasn't 100% sure that would do the trick :)
t00ny