CodeIgniter不理解在两个更新查询中的位置 [英] CodeIgniter doesn't understand where in two update queries

查看:113
本文介绍了CodeIgniter不理解在两个更新查询中的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模型中有两个函数。第一个:

I have two functions in my model. First one:

    public function updateOwn($game,$own,$user) {

    $data = array(
        'own' => $own
    );

    $q = $this->db->where(array(
        'game' => $game,
        'user' => $user
    ));

    $q = $this->db->update('ownership',$data);

    if($q) { return true; } else { return false; }
}

和第一个:

    public function updateRate($game,$rate,$user) {

    $data = array(
        'rate' => $rate
    );

    $q = $this->db->where(array(
        'game' => $game,
        'user' => $user
    ));

    $q = $this->db->update('rates',$data);
    $q = $this->db->update('ownership',$data);

    if($q) { return true; } else { return false; }
}

问题是,第一个是工作,第一个不工作。我的意思是,它工作,但它更新每一行,而不只是匹配游戏用户的那些。

The problem is, first one is working, secound one isn't. I mean, it works, but it updates every row, not just those with matching game and user. Variables are passed fine.

推荐答案

where条件仅适用于第一个update语句。请尝试以下操作。

The where condition is only applied to the first update statement. Try below.

$data = array(
    'rate' => $rate
);

$where = array(
    'game' => $game,
    'user' => $user
);

$q = $this->db->update('rates', $data, $where);
$q = $this->db->update('ownership', $data, $where);

这篇关于CodeIgniter不理解在两个更新查询中的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆