1

我正在尝试选择 ids 并将其传递给更新使用这个

$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

1 回答 1

4

You should pass an array there. So pass not $sponsorids->sponstr but explode(',', $sponsorids->sponstr)

Also it's seems like a bad DB design decision, take some time and have a look on many-to-many concept

于 2013-06-19T01:49:02.417 回答