如何返回数组?这是我的代码(这是在模型中)
function getTeacherSchedule($id){
$sections = $this->dbsections->query('SELECT * FROM sections;');
foreach ($sections->result_array() as $section){
$table = $section['NAME'];
$tblsection = str_replace(array(' ', '-'),'_', $table);
$schedule = ($this->dbsections->query('SELECT * FROM '.$tblsection.' WHERE TEACHER = '.$id));
$result = $schedule->result_array();
}
return $result;
}
我希望$ schedule的result_array()在控制器中返回,但是当我尝试var_dump()它时,它只返回一条记录。
答案 0 :(得分:0)
目前,您正在存储单个记录并在每个循环中覆盖它。试试 -
function getTeacherSchedule($id){
$sections = $this->dbsections->query('SELECT * FROM sections;');
foreach ($sections->result_array() as $section){
// rest of the code
// .......
$result[] = $schedule->result_array();
}
return $result;
}