Error durante la ejecución de esta función

Posible duplicado:
Mensaje: Argumento no válido proporcionado para foreach en CodeIgniter

Continuar del mensaje: argumento no válido proporcionado para foreach en CodeIgniter .

Esta es la función, de la que provienen los $ datos ..

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

Lo más probable es que su result esté regresando vacío. Cambiar a

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