views:

30

answers:

1

I am running a query with Active Record in a modal of my codeigniter application, the query looks like this,

public function selectAllJobs()
{
    $this->db->select('*')
             ->from('job_listing')
             ->join('job_listing_has_employer_details', 'job_listing_has_employer_details.employer_details_id = job_listing.id', 'left');
             //->join('employer_details', 'employer_details.users_id = job_listing_has_employer_details.employer_details_id');

    $query = $this->db->get();
    return $query->result_array();
}

This returns an array that looks like this,

    [0]=>
  array(13) {
    ["id"]=>
    string(1) "1"
    ["job_titles_id"]=>
    string(1) "1"
    ["location"]=>
    string(12) "Huddersfield"
    ["location_postcode"]=>
    string(7) "HD3 4AG"
    ["basic_salary"]=>
    string(19) "£20,000 - £25,000"
    ["bonus"]=>
    string(12) "php, html, j"
    ["benefits"]=>
    string(11) "Compnay Car"
    ["key_skills"]=>
    string(1) "1"
    ["retrain_position"]=>
    string(3) "YES"
    ["summary"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["description"]=>
    string(73) "Lorem Ipsum is simply dummy text of the printing and typesetting industry"
    ["job_listing_id"]=>
    NULL
    ["employer_details_id"]=>
    NULL
  }
}

The job_listing_id and employer_details_id return as NULL however if I run the SQL in phpmyadmin I get full set of results, the query i running in phpmyadmin is,

    SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id`
LIMIT 0 , 30

Is there a reason why I am getting differing results?

+3  A: 

Run the $this->db->last_query() and check the difference. It's a very useful debugging tool.

Of course the limit will have an effect, but I'm ignoring that.

It seems in your query in phpmyadmin, your 'ON' doesn't have a second part. I think your query in phpmyadmin should be:

SELECT *
FROM (
`job_listing`
)
LEFT JOIN `job_listing_has_employer_details` ON `job_listing_has_employer_details`.`employer_details_id` =  = `job_listing`.`id`

You should be using result_array, despite what the other person said.

Michael Ozeryansky