开发者

Codeigniter num_row returns "array" instead of number

开发者 https://www.devze.com 2023-01-09 21:09 出处:网络
Alright, Im trying to count all the rows where \"Membership_Status\" = Active. The result I get right now is \"Array\" instead of a number.

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'] = 're开发者_高级运维port_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


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; ?>
0

精彩评论

暂无评论...
验证码 换一张
取 消