我无法在我的视图页面中获得$ result ['query']

时间:2015-07-14 07:39:14

标签: codeigniter

我的控制器Erp_c:

$result['query2']= $this->erp_m->selectattend1($user,$en,$year,$month);
$this->load->('salview',$result);

在模型Erp_m中:

function selectattend1($user,$en,$year,$month)
{
  $query2=$this->db->query(" SELECT COUNT(*)
FROM attendance3
WHERE name = '$en'
AND attend = 'Absent'
AND MONTH = '$month'
AND year = '$year'
AND user = '$user' ");

return $query2->result(); 

}

在视图页面salview.php中:

 foreach($query2 as $row)

{
$al=$row->count(*);///here what i put ,that is my doubt
,because $result['query']= Array ( [0] => stdClass Object ( [COUNT(*)] => 1 ) )
}

如何在视图页面中获取计数值?

1 个答案:

答案 0 :(得分:0)

在控制器

$result['query2']= $this->erp_m->selectattend1($user,$en,$year,$month);//get data
$result['count']= $this->erp_m->get_selectattend1_count($user,$en,$year,$month);//get count

在模型中

function selectattend1($user,$en,$year,$month)
{
    $query2 = $this->db->query(" SELECT COUNT(*)
            FROM attendance3
            WHERE name = '$en'
            AND attend = 'Absent'
            AND MONTH = '$month'
            AND year = '$year'
            AND user = '$user' ");

    $result = $query2->result_array();
    return $result;
}

function get_selectattend1_count($user,$en,$year,$month)
{
    $query2 = $this->db->query(" SELECT COUNT(*)
            FROM attendance3
            WHERE name = '$en'
            AND attend = 'Absent'
            AND MONTH = '$month'
            AND year = '$year'
            AND user = '$user' ");

    $result = $query2->result_array();
    $count = count($result);
    return $count;
}

在视图中

您可以同时访问$query2$count

这两个变量
foreach($query2 as $row)
{
    echo $row['field_name'];
}