Pardeep Pardeep - 4 months ago 11
PHP Question

passing an array from model to controller

In my model i am getting all emails in a array and i want to show this array of emails in controller not in view.
Here my model is

public function cron_job(){
$this->db->select('email');
$this->db->from('wc_buyer');
$query = $this->db->get();
return $query;
}


and controller is

public function cron_job(){
$this->load->model('home/Home_model');
$data['a'] = $this->Home_model->cron_job();
}


how can i show this print this array of emails in variable in controller

Answer

Try like this

     public function cron_job(){
             $this->db->select('email');
             $this->db->from('wc_buyer');
             $query = $this->db->get();
             $result = array();
             foreach ($query->result() as $row){
                $result[] = $row;
             }
             return $result; 
        }

 public function cron_job(){
    $this->load->model('home/Home_model');
    $data['a'] = $this->Home_model->cron_job();
    print_r($data['a']);
}
Comments