我正在尝试选择ID并使用此
将其传递给更新$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都不会更新,只有第一个ID会更新。
where_in生成下面的代码
WHERE sponsor_id IN ('5,4,2,3,1')
我认为它应该是
WHERE sponsor_id IN (5,4,2,3,1)
我在这里遗漏了什么,或者我做错了什么,显然我知道我是。请帮忙
答案 0 :(得分:4)
你应该在那里传递数组。所以不要通过$sponsorids->sponstr
而是explode(',', $sponsorids->sponstr)
此外,这似乎是一个糟糕的数据库设计决策,花一些时间看看多对多的概念