在模型null中调用函数

时间:2016-01-25 02:44:42

标签: php mysql codeigniter

我正在尝试获取sql表的count()。但是,我一直收到这个错误。

  

在null

上调用成员函数master_banner()

如何更改代码?

控制器

public function index()
    {
        //$this->landing_banners_upload();
        $config["total_rows"] = count($this->Backend_banner_model->master_banner_list());       
        $config["per_page"] = 1;
        $config["uri_segment"] = 3;

        $this->pagination->initialize($config);     
        $data['per_page']= $config["per_page"];
        $data["no_pages"] = $config['total_rows']/$config['per_page'];
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;      
        $offset=$page+$config["per_page"];          
        $data['banners']=$this->Backend_banner_model->master_banner($page,$offset);     
        count($data['banners']);
        $data["links"] = $this->pagination->create_links();

        echo $data["links"];

        $this->load->view('layout/header');
        $this->load->view('backendBanner/landing_banners_upload_view', $data);
        $this->load->view('layout/footer');
    }

模型

public function master_banner_list(){
        $sql="select * from banner";                                    
        $query = $this->db->query($sql);
        $data   =   array();
        if ($query->num_rows() > 0){
            foreach ($query->result() as $row) {
                $data[] = $row;
            }           
        }   
        return $data; 
    }

    public function master_banner($start,$offset){
            $sql="SELECT * FROM banner
                    WHERE RowNum > '".$start."' AND RowNum <= '".$offset."'";

            $query = $this->db->query($sql);

            $data   =   array();
            foreach ($query->result() as $row) {

                $data[] = $row;
            }
            return $data;   
    }   

0 个答案:

没有答案