我不能得到$结果['查询']在我的视图页面 [英] I cant get $result['query'] in my view page

查看:117
本文介绍了我不能得到$结果['查询']在我的视图页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的控制器Erp_c:

My controller 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:

In view page 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 ) )
}

如何在查看页面中获取计数值?

How can I get count value in view page?

推荐答案

在控制器中

$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

you can access both veriables $query2 and $count

foreach($query2 as $row)
{
    echo $row['field_name'];
}

这篇关于我不能得到$结果['查询']在我的视图页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆