0

Very simple stuff here, I'm new to CI. I have the following:

Model

 class Stockists_model extends CI_Model {

    public function __construct() {
        parent::__construct();  
    }

    function stockists_all() {
        return $this->db->get('stockists')->result();
    }
 }

Controller

    $data['stockists'] = $this->Stockists_model->stockists_all();
    $this->load->view($this->data['system_settings']['admin_folder']  .'/stockists', $this->data);

View

foreach($stockists as $stockist) {
    echo $stockist->Shp_num_an;
    echo $stockist->Postcode;
}

But I get the error:

Undefined variable: stockists

and

Invalid argument supplied for foreach()

Can anyone see an issue here?

6
  • Do you have data in your table??? and use !empty($stockists) in view before foreach loop Commented Jan 8, 2016 at 9:14
  • can you please do in your view var_dump($stockists) and post your results here? Commented Jan 8, 2016 at 9:16
  • which line display the Undefined variable: stockists error ? Commented Jan 8, 2016 at 9:20
  • Stockists is empty, this seems to be the issue. If I do an 'if $stockists has has value) I get: "Undefined variable: stockists" Commented Jan 8, 2016 at 9:24
  • $this->data this should be $data Commented Jan 8, 2016 at 10:24

1 Answer 1

2

if you are getting your data in $data['stocklists] then send data to page by

$this->load->view($this->data['system_settings']['admin_folder']  .'/stockists',array('data'=>$data));

and on other page retreive data from array by

$stocklists=$data['stocklists']; 

It will work if you are having table in $data['stocklists']

Good Luck!!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.