Updating and merging a query together in codeigniter?

Updating data when joining two tables, but it gives an error when a condition can I use join and update together in a query?

here is my code

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();
}

I got an error as shown below in my mysql

Fatal error: failed Error: calling the 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 \\ Kernel system \ CodeIgniter.php (360): User-> updateSave ('1') # 2 C: \ xampp \ htdocs \ P_Display \ index.php (202): require_once ('C: \ xampp \ htdocs ...') # 3 {main} selected C: \ xampp \ htdocs \ P_Display \ application \ models \ Pmodel.php on line 103

where ?

+4
2

@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;


}

, , .

+2

$this->db>where('user_data.id',$id);//see here missing arrow

$this->db->where('user_data.id',$id);

UPDATE

.

$sql = "UPDATE user_data AS ud JOIN user AS u ON ud.id = u.id SET ud.col1 = val1,ud.col2 = val2 WHERE ud.id = $id";
$this->db->query($sql);

$this->db->join('user_data', 'user.id = user_data.id');
$this->db->set($data);
$this->db->where('user_data.id',$id);
$this->db->update('user_data');
+4

Source: https://habr.com/ru/post/1670205/


All Articles