好吧,我试图计算“Membership_Status”= Active的所有行 . 我现在得到的结果是“数组”而不是数字 .
这是我的模特
class Report_model extends Model
{
function count_members()
{
$query = $this->db->get_where('Membership', array('Membership_Status' => 'Active'));
return $query->num_rows();
}
}
这是我的控制器
class Report extends Controller {
function YTD_report()
{
$data['main_content'] = 'report_membership_view';
$this->load->view('includes/template', $data);
}
}
这是我的看法
report_model->count_members();
echo $total;
?>
我的结果是Array,根据db信息,它应该是4 .
我可以做什么/改变它来显示正确的数字?
谢谢
1 回答
传递给视图的$ data数组将为视图使用的每个键创建一个变量...
所以你的控制器 once the model is loaded ,你应该这样做:
然后在视图中,您可以使用$ total变量,如下所示: