简体   繁体   English

Codeigniter返回数组

[英]Codeigniter return array

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. 我希望在控制器中返回$ schedule的result_array(),但是当我尝试使用var_dump()时,它只返回一条记录。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM