连接两个表时更新数据,但在 where 条件下出现错误
我可以在查询中同时使用连接和更新吗?
这是我的代码
public function update_model($id,array $data)
{
//$textArea=$data['textdata'];
$this->db->join('user_data', 'user.id = user_data.id');
$this->db>where('user_data.id',$id);
$this->db->update('user_data',$data);
$query=$this->db->get();
return $query->result();
}
我的 mysql 中出现如下错误
致命错误:未捕获错误:调用未定义函数 where() in
C:\xampp\htdocs\P_Display\application\models\Pmodel.php:103 堆栈
跟踪:#0
C:\xampp\htdocs\P_Display\application\controllers\user.php(124):
Pmodel->update_model('1', 数组) #1
C:\xampp\htdocs\P_Display\system\core\CodeIgniter.php(360):
用户->updateSave('1') #2 C:\xampp\htdocs\P_Display\index.php(202):
require_once('C:\xampp\htdocs...') #3 {main} 抛出
C:\xampp\htdocs\P_Display\application\models\Pmodel.php 第 103 行
where 子句给了我一个错误,使用这个查询是否正确?
感谢@HekMet 的回复
现在我得到了代码,但以不同的方式查看它,如果您发现它有问题,请告诉我..
public function update_model($id,array $data)
{
$uname=$data['uname'];
$email=$data['email'];
$password=$data['password'];
$address=$data['address'];
$mobilenumber=$data['Mobilenumber'];
$job=$data['Job'];
$query=
$this->db->set('user_data.email',$email);
$this->db->set('user.password',$password);
$this->db->set('user_data.mobilenumber',$mobilenumber);
$this->db->set('user_data.job',$job);
$this->db->set('user.uname',$uname);
$this->db->where('user_data.id',$id);
$this->db->where('user.id',$id);
$this->db->update('user_data JOIN user ON user_data.id= user.id');
return $query;
}
因为它给出了我的变量不明确的错误,所以我需要单独设置它们的值。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)