AyeTry
AyeTry

Reputation: 75

Unable to pass variable from codeigniter controller to the view?

At the moment I have a controller which should send a variable holding an array to my view but this currently is not happening.

There is no actual data/rows within this mySQL table and I don't know if that may be the reason that it shows the following error: Message: Undefined variable: jobs in views/applicantjobs.php

controller: applicantjobs.php

$employer_jobs = $this->db->get_where('jobs', array('employer_profile_id' => $user['id'] ));
$jobs = $employer_jobs->result_array();

$this->load->view('header');
$this->load->view('applicantjobs', $jobs);

view: applicantjobs.php

foreach($applicantjobs as $applicantjob){
    echo $applicantjob['name'];
}

Any help is really appreciated, thank you!

Upvotes: 0

Views: 822

Answers (1)

DeiForm
DeiForm

Reputation: 664

$data['jobs'] = $this->db->get_where('jobs', array('employer_profile_id' => $user['id'] ))->result_array();

$this->load->view('applicantjobs', $data);

Try this one

And in your view:

foreach($jobs as $job)
{
   echo $job['name'];
}

Upvotes: 2

Related Questions