-1

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

消息继续:为 CodeIgniter 中的 foreach 提供的参数无效

这是 $data 来自的函数..

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();  
   }
4

1 回答 1

0

您最有可能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();  
   }
于 2012-11-19T05:57:38.133 回答