可能重复:
Message: Invalid argument supplied for foreach in CodeIgniter
从Message: Invalid argument supplied for foreach in CodeIgniter继续。
这是$ 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();
}
答案 0 :(得分: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();
}