Codeigniter num rows错误

时间:2015-09-25 14:56:35

标签: php codeigniter

当我运行此代码时,它工作正常

  echo $str = $this->db->last_query();

此行之后

 if($selectRecords->num_rows()>0){
 //some action
}

我正在接受此错误

<br />
<b>Fatal error</b>:  Call to undefined method CI_DB_mysql_driver::num_rows() in <b>/vagrant/application/controllers/applicationtable.php</b> on line <b>1240</b><br />

这是我的代码

<?php
    public function xyz(){
            $selectRecords=$this->db->select(" (SELECT name FROM $this->reportTable WHERE id=$this->reportType) AS `$this->reportLabel`, 
                        SUM(rashi_given) AS `total` ,
                        SUM(rashi_accepted) AS atotal");
              $selectRecords->join('type', 'applicants.type=type.id', 'left');
              $selectRecords->group_by($this->reportType); 
              $selectRecords->get('applicants');
             echo $str = $this->db->last_query(); 
          if($selectRecords->num_rows()>0){

           }
     }


    ?>

有什么问题请帮忙

1 个答案:

答案 0 :(得分:2)

你正在检查错误的变量。见Call to undefined method CI_DB_mysql_driver::num_rows()

$rs = $selectRecords->get('applicants');
echo $str = $this->db->last_query(); 

if($rs->num_rows()>0){

}