当我尝试这段代码时:
$query = '';
foreach ($data as $row)
{
$where = array(
'community_id' => $row->id,
'user_id' => $this->session->user_id,
'status' => 'invited_to_join',
);
$update = array(
'status' => 'joined',
);
$query .= $this->db->set($update)->where($where)->get_compiled_update('community_members').'; ';
}
if ($query)
{
return $this->db->query($query);
}
它给了我错误:
您的SQL语法有错误;检查手册 对应于您的MariaDB服务器版本,以获得正确的语法 接近'更新
community_members
设置status
='加入'哪里community_id
=' 18'甲'在第4行
this answer使用CASE直接查询,但我不知道如何将其转换为Codeigniter的查询生成器。
答案 0 :(得分:4)
试试这个例子;
你可以像这样直接使用数组$data['id']
,不需要在这里使用循环作为我的opine
$this->db->set('status','joined');
$this->db->where('community_id',$data['id']);
$this->db->where('user_id',$this->session->user_id);
$this->db->where('status','invited_to_join');
$this->db->update('community_members');
答案 1 :(得分:2)
您也可以这样使用 $where = "'community_id'=".$data['id']." AND user_id=".$this->session-user_id." AND status='invited_to_join'";
$this->db->set('status','joined');
$this->db->where($where);
$this->db->update('community_members');
子句:
const Schema = new GraphQLObjectType({
name: "Mutation",
description: "Mutation schema",
fields() {
return {
// Add user
addUser: {
type: UserSchema,
args: () => {
return {
firstName: {
type: GraphQLString
}
};
},
resolve(_, args){
return Db.models.user.update( () => {
return _.mapValues(args, (v, k) => {
return args[k];
});
}, {
returning: true
});
}
}
};
}
});
谢谢!!!