help with matching array keys overwriting each other

Question!

I have a problem with an array that is getting returned from a query I am running,

    $jobs = array(
  array('id'=>2,'salary'=>27000,'benefits'=>'false','benefits_description'=>'','skills'=>'PHP mysql javascript','job_summary'=>'Developing stuff','job_description'=>'Developing stuff','tags'=>'PHP, mysql, web development, web, leeds','created_at'=>1294871124,'updated_at'=>0,'job_titles_id'=>1,'locations_id'=>1,'employers_id'=>4,'id'=>1,'jobtitle'=>'Website Developer','id'=>1,'location'=>'Leeds')
);

I wanting to use the first id in my link I am building, however instead of 2 it is returning 1 as I assume that the first id is getting overwritten by ID's later in the array? Is there any way to stop this happening, I cannot change my database schema at this stage of the project, the query that gets this from the database looks like this,

$this->db->select('*')
        ->from('jobs')
        ->join('job_titles', 'job_titles.id = jobs.job_titles_id', 'left')
        ->join('locations', 'locations.id = jobs.locations_id', 'left')
        ->where('jobs.employers_id', $employer_id);

        $query = $this->db->get();

        return $query->result_array();
By : sea_1987


Answers

You need to alias the field you're getting back from the database.

You've not specified what RDBMS you're using, but chances are it's MySQL so instead of using a SELECT * (which is lazy and bad practice to be honest), you should specifiy the fields you specifically require and can alias the second ID field using something of the form:

SELECT ... 


This video can help you solving your question :)
By: admin