在Codeigniter中一起更新和联接查询? [英] Update and Join query together in codeigniter?

查看:78
本文介绍了在Codeigniter中一起更新和联接查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在连接两个表时更新数据,但是在where条件下会出现错误 我可以在查询中使用联接和一起更新吗?

Updating data while join two tables but it gives an error in where condition can i use join and update together in a query ?

这是我的代码

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中遇到如下错误

I got Error like below in my mysql

致命错误:未捕获错误:调用未定义函数where() C:\ xampp \ htdocs \ P_Display \ application \ models \ Pmodel.php:103堆栈 跟踪:#0 C:\ xampp \ htdocs \ P_Display \ application \ controllers \ user.php(1‌24): Pmodel-> update_model('1',数组)#1 C:\ xampp \ htdocs \ P_Display \ system \ core \ CodeIgniter.php(360): User-> updateSave('1')#2 C:\ xampp \ htdocs \ P_Display \ index.php(202): require_once('C:\ xampp \ htdocs ...')#3 {main}被抛出 第103行的C:\ xampp \ htdocs \ P_Display \ application \ models \ Pmodel.php

Fatal error: Uncaught Error: Call to undefined function where() in C:\xampp\htdocs\P_Display\application\models\Pmodel.php:103 Stack trace: #0 C:\xampp\htdocs\P_Display\application\controllers\user.php(1‌​24): Pmodel->update_model('1', Array) #1 C:\xampp\htdocs\P_Display\system\core\CodeIgniter.php(360): User->updateSave('1') #2 C:\xampp\htdocs\P_Display\index.php(202): require_once('C:\xampp\htdocs...') #3 {main} thrown in C:\xampp\htdocs\P_Display\application\models\Pmodel.php on line 103

where子句给我一个错误,使用此查询是否正确?

the where clause is giving me an error and is it correct to use this query ?

推荐答案

感谢@HekMet的回复

Thanks @HekMet for your reply

现在我得到了代码,但是以另一种方式看了它,让我知道您是否发现了问题.

now i got the code but in a different way lok at it and let me know if you found some problem with it..

 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;


}

由于错误提示我的变量不明确,我只需要分别设置它们的值即可.

since it was giving error that my variable are ambigious i need to just set their values separatly.

这篇关于在Codeigniter中一起更新和联接查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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