该功能的执行期间,错误[复制](Error during execution of this fun

2019-08-02 22:06发布

可能重复:
消息:CI中提供的foreach无效的参数

从继续消息:CI中提供的foreach为无效的参数 。

这是函数,从中$ datais未来..

function getSearchedUniversityTab($country, $state, $level, $degType) {
      $query = $this->db->query("SELECT `university`.`uniId`, `university`.`name`
                                FROM (`university`)
                                inner JOIN (select degCollege, degType, count(*) as cnt  from degree where `degType` =  '$degType'  group by degCollege) clg
                                ON clg.`degCollege` = `university`.`uniId` 
                                WHERE `country` =  '$country'
                                AND `state` =  '$state'");
      $result = $query->result_array();

      foreach($result as $row)
      {
        $data[] = $row;
      }
      return $data;
      $this->db->close();  
   }

Answer 1:

最有可能的result将返回空更改为

function getSearchedUniversityTab($country, $state, $level, $degType) {
      $query = $this->db->query("SELECT `university`.`uniId`, `university`.`name`
                                FROM (`university`)
                                inner JOIN (select degCollege, degType, count(*) as cnt  from degree where `degType` =  '$degType'  group by degCollege) clg
                                ON clg.`degCollege` = `university`.`uniId` 
                                WHERE `country` =  '$country'
                                AND `state` =  '$state'");
      $result = $query->result_array();
     if(count($result) > 0 ) {
      foreach($result as $row)
      {
        $data[] = $row;
      }

      return $data;
     }else{
       return null;
     }
      $this->db->close();  
   }


文章来源: Error during execution of this function [duplicate]