0

I have the following:
in my MODEL:

function get_advert() {
    $sql = "SELECT * FROM job_advert";
    $advert = $this->db->query($sql)->result();
    return $advert;
}

in my CONTROLLER:

function get_detailed_list() {
   $job_advert = $this->ranking_model->get_advert();
   echo '<pre>';

    foreach ($job_advert as $j) {
        $job_id = $j->advert_id;
        $sql = "SELECT r.rank, a.advert_id AS job_id, a.job_title, d.firstname, d.uacc_email, d.id_number AS app_id
FROM rank_results AS r 
    INNER JOIN job_advert AS a 
        ON r.job_id = a.advert_id 
    INNER JOIN applicant_details AS d 
        ON r.applicant_id = d.id_number
WHERE a.advert_id = '{$job_id}'       
ORDER BY r.rank, d.firstname";
        $results[] = $this->db->query($sql)->result();

return $results;

}

public function index() {

    $data['content'] = 'admin/ranking/ranking';
    $data['results'] = $this->get_detailed_list();
    $this->load->view('admin/ranking/ranking',$data);
}

in my VIEW:

foreach ($results as $key =>$job) {
    print_r($job);                 // This is working
    $job_tilte = $job->job_title;  // This is not working
    $j_id = $job->job_id;
    $name = $job->firstname;
    $id_number = $job->app_id;
    $applicant_email = $job->uacc_email;
    $rank = $result->rank;
    }

I dont understand why I'm getting the error: Trying to get property of non-object even though print_r($job) displays that it is

    Array
(
    [0] => stdClass Object
   ...

and when I change $job->job_title; to $job['job_title']; I get Undefined index: job_title
Can some one please help me? I cant seem to find my error and its starting to frustrate me...
Thanks in advance.

Edited by renierdbruyn: updated title. made it more descriptive

2
Contributors
1
Reply
25
Views
4 Years
Discussion Span
Last Post by diafol
2

Try this...

foreach ($results as $key =>$job) {
    print_r($job);                 // This is working
    echo "<br />" . $job[0]->job_title . "<br />";
    echo $job[0]->job_id . "<br />";
    echo $job[0]->firstname . "<br />";
    echo $job[0]->app_id . "<br />";
    echo $job[0]->uacc_email . "<br />";
    //echo $result->rank; is this right? or is it $results->rank ??
}
exit();

See if you get any meaningful output.

Edited by diafol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.