2013-06-19 71 views
1

我想選擇的ID,並通過使用該通選擇進入where_in笨

$query = $this->db->query("SELECT GROUP_CONCAT(a.sponsor_id) as sponstr FROM (select sponsor_id from sponsor WHERE (pay_success = 'yes')AND (end_date_time > NOW()) and ((country_id = 1 and state_id = 24) or city_id = 123) 
order by rand() limit 0,10) a"); 

    if($query->num_rows()>0) 
    { 
    foreach($query->result() as $sponsorids) 
    { 

     $data['se_count'] = 0; 
     $this->db->where_in('sponsor_id',$sponsorids->sponstr); 
     $this->db->update('sponsor',$data); 

    } 
    } 

,但所有的ID不更新它傳遞到更新,只有第一個做。

的where_in產生以下

WHERE sponsor_id IN ('5,4,2,3,1') 

的代碼,我認爲它應該是

WHERE sponsor_id IN (5,4,2,3,1) 

我錯過了什麼這裏還是我做錯什麼,這顯然我知道我。請幫忙

回答

4

你應該在那裏傳遞一個數組。所以,不要過$sponsorids->sponstrexplode(',', $sponsorids->sponstr)

而且它似乎是一個糟糕的DB設計決策,需要一些時間,看看許多一對多概念

+0

非常感謝你 – dansasu11