How to return an array? This is my code (this is inside the model)
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;
}
And I want the result_array() of $schedule to be returned in a controller, but when i try to var_dump() it, it only returns a single record.
Currently you are storing a single record and overwriting it in every loop. Try -
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.