Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 "<br>";
    echo form_open('job/view' . '" id="eachJob');

    echo "<div id=\"leftContain\" class=\"floatLeft\">";
    echo "<h4 class=\"green\">" . $job['role'] . "</h4>";
    echo "<div class=\"italic\"><div class=\"blue floatLeft\">" . $job['company']
        . " &nbsp; </div><div class=\"floatLeft\">in</div><div class=\"blue floatLeft\"> &nbsp; "
        . $job['location'] . "</div></div><br><br>";
    echo "</div>";

    echo "<div id=\"rightContain\" class=\"floatLeft\">";
    echo "<input type=\"hidden\" name=\"job_id\" value=\"" . $single_job_id . "\">";
    echo form_submit('submit' . '" class="jobButton floatRight"', 'View Job');
    echo "</div>";

    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.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

You are correct:

$data['jobs'] .= $data['job'];

concatenates strings, not arrays, and will never work.

Instead, try something like:

$data['jobs'][] = $data['job'];

to build up an array of the jobs, then output with a foreach() or whatever is most suitable

share|improve this answer
 
many thanks, it worked perfectly. –  learn Sep 1 at 11:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.