help with matching array keys overwriting each other


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,

        ->join('job_titles', ' = jobs.job_titles_id', 'left')
        ->join('locations', ' = jobs.locations_id', 'left')
        ->where('jobs.employers_id', $employer_id);

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

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


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:


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