3

我有两张桌子:

表 1:id、user_id、poll_id、options_id

表 2:id、poll_id、投票

列 votes 是一个整数,我想通过将表与一些 where 子句连接来更改值:

$this->db
->set('votes', 'votes - 1', FALSE)
->join('table1', 'poll_votes.options_id = table2.id')
->where('poll_id', $row)
->where('user_id', $id)
->update('table2');

我收到此错误:

错误号:1054
'where 子句'中的未知列'user_id'
更新 `table2` SET votes = votes - 1 WHERE `poll_id` = '9' AND `user_id` = '1'
4

2 回答 2

9

试试这个:

$this->db->set('votes', 'votes - 1', FALSE)
$this->db->where('table1.user_id',$id);
$this->db->where('table2.poll_id',$row);
$this->db->update('table1 join table2 ON table1.poll_id= table2.poll_id');
于 2013-07-30T18:22:27.647 回答
0

试试这个。它对我有用!!!

$data = array(
    'a.ED_FName' => $_POST['firstname'],
    'a.ED_MName' => $_POST['middlename'],
    'a.ED_LName' => $_POST['lastname'],
    'a.ED_Location' => $_POST['location'],
    'a.ED_Company' => $_POST['company'],
    'b.EMD_Department' => $_POST['department']
);

$this->db->set($data);

$this->db->where('a.EmpID', $empID);

$this->db->where('b.EmpID', $empID);

$this->db->update('tbl_employeedetails as a, tbl_employeementdetails as b');

最好的问候, 图沙尔尼拉斯

更新:

注意:切勿使用 $_POST、$_GET 等包含用户请求数据的全局数组,而无需进行安全检查。这可能会导致 SQL 注入等严重问题。

于 2015-06-27T09:53:30.770 回答