dpp80346 2014-06-14 08:07
浏览 30
已采纳

如何在标准中获得计数字段?

I'm trying to build a query that has a group by user_id, select user_id,count(id) , condition, join. i can get a true result by findall command but only i can not show count(id) i left my code here

in controller

       $criteria=new CDbcriteria();
        $criteria->condition = 'serviceId=:serviceId';
        $criteria->params = array(':serviceId'=>1);
        $criteria->group = 't.user_Id';
        $criteria->select = array('t.user_Id,count(psh_profile_information_services.id) AS count');
        $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileInformationId';
        $moli=  ProfileInformation::model()->findAll($criteria);
        $this->render('conectionpoint', array('moli'=>$moli ));

in view

foreach ($moli as $mol)
        {
            echo "user_Id:  ".$mol->user_id." --- count:".???????? ;

        }

print $mol

ProfileInformation Object ( [_new:CActiveRecord:private] => [_attributes:CActiveRecord:private] => Array ( [user_Id] => 1 [createDate] => 1393/03/23 - 15:49:26 [modifiedDate] => 1393/03/23 - 15:49:26 ) [_related:CActiveRecord:private] => Array ( ) [_c:CActiveRecord:private] => [_pk:CActiveRecord:private] => [_alias:CActiveRecord:private] => t [_errors:CModel:private] => Array ( ) [_validators:CModel:private] => [_scenario:CModel:private] => update [_e:CComponent:private] => [_m:CComponent:private] => )
  • 写回答

1条回答 默认 最新

  • duanmei2805 2014-06-14 10:51
    关注

    In ProfileInformation class file -

    class ProfileInformation extends ActiveRecord
    {
        $public $total_info;
        [....] //Rest of the code.
    

    In Controller Action, change -

    $criteria->select = array('t.user_Id,count(psh_profile_information_services.id) AS count');

    to

    $criteria->select = array('t.user_Id,count(psh_profile_information_services.id) AS total_info');

    In view file -

    foreach ($moli as $mol)
    {
        echo "user_Id:  ".$mol->user_id." --- count:".$mol->total_info;
    }
    

    This should work fine.

    If not, then just do simple debug -

    echo "<pre>";
    
    foreach($moli as $mol) {
        echo 'Total Info: ' . $mol->total_info . "<br />";
        foreach($mol as $key => $value) {
            echo $key . ' ' . $value . "<br />";
        }
        echo "<br />";
    }
    
    exit();
    

    and check the values.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?