Adding row_array to result_array foreach loop with codeigniter?-Collection of common programming errors
I currently have a function on a web app which I’m building where a jobseeker can view the jobs they have applied for, very simple.
When they “apply” this application is stored in the database table ‘applications’ with a ‘job_id’ column which stores the ‘id’ of the job from the ‘jobs’ database table.
At the moment I am able to pull each application the said jobseeker has made.
Though, I am unable to loop through each application and find the job which corresponds to that application and then add the row_array() to larger array which I will then output the jobs with a foreach loop.
Essentially I am asking how do I add an array to an array and then output the full array?
appliedfor.php (CONTROLLER)
$applications_query = $this->db->get_where(
'applications', array('jobseeker_profile_id' => $user['id'])
);
$applications = $applications_query->result_array();
$data[] = array();
foreach ($applications as $application) {
$job_id = $application['job_id'];
$data['job'] = $this->db->get_where('jobs', array('id' => $job_id))->row_array();
$data['jobs'] .= $data['job'];
}
$data['jobs'];
$this->load->view('header');
$this->load->view('appliedfor', $data);
appliedfor.php (VIEW)
foreach ($jobs as $job) {
$single_job_id = $job['id'];
echo "
";
echo form_open('job/view' . '" id="eachJob');
echo "";
echo "
" . $job['role'] . "
"; echo "" . $job['company'] . " in " . $job['location'] . "
"; echo ""; echo ""; echo ""; echo form_submit('submit' . '" class="jobButton floatRight"', 'View Job'); echo ""; echo form_close(); }
I am currently getting 2 errors: Undefined index: jobs and the error is on this line apparently
$data['jobs']
in the controller within the foreach.
The other error is the foreach within the view file but that is basically triggered by the first error.
Thanks for your help.