开发者

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 stu开发者_开发问答ff','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();


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 ... <table name>.<field name> AS id_2 ... FROM ...

Here's the relevant MySQL manual page for more information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜