2011-01-13 48 views
0

我有,這是獲得從我運行一個查詢返回數組的一個問題,幫助有相同排列的鍵互相覆蓋

$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') 
); 

我想使用的第一個ID在我的鏈接我建立,然而,而不是2它返回1,因爲我認爲第一個ID被數組後面的ID覆蓋?有沒有什麼辦法阻止這種情況發生,我不能在這個階段的項目,應該得到這個從數據庫中看起來像這樣的查詢更改我的數據庫架構,

$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(); 

回答

1

你需要別名你的場從數據庫中回來。

您尚未指定您正在使用的RDBMS,但有可能是MySQL,因此您不應使用SELECT *(這是懶惰和不正確的做法),您應該指定您特別需要的字段並可以使用別名使用形式的東西第二ID字段:

SELECT ... <table name>.<field name> AS id_2 ... FROM ... 

下面是詳細信息相關MySQL manual page