logo
down
shadow

How to use Join in Codeigniter for update Query


How to use Join in Codeigniter for update Query

By : user2185108
Date : November 20 2020, 04:01 AM
I wish this help you I have given my Codeigniter code below, here i need to update a record using join conditions. I used the below code, But shows error , Try this:
code :
$sql = "UPDATE tq_customerservicesupport AS a JOIN tq_customer AS b ON a.customerid = b.customerid JOIN tq_product AS c ON  a.productid = c.productid SET $data WHERE $condition ORDER BY a.created_on ASC LIMIT $limit";
$this->db->query($sql);


Share : facebook icon twitter icon
Codeigniter $this->db->join used with $this->db->update

Codeigniter $this->db->join used with $this->db->update


By : Jianguo.Ye
Date : March 29 2020, 07:55 AM
it fixes the issue Ok well I managed to find a "clean" solution, using codeigniter's join, set, etc. So what's cool is that you will have all CI's benefits of using $this->db->join(), $this->db->join(), etc. like escaping and adding quotes.
So first do all your CI stuff:
code :
$this->db->join(..) // Set all your JOINs
$this->db->set(..) // Set your SET data
$this->db->where(..) // Set all your WHEREs
// JOIN
$sql = "UPDATE $this->baseTable ";
$sql .= implode(' ', $this->db->ar_join);

// SET
$sql .= ' SET';
$setArray = array();
foreach ($this->db->ar_set as $column=>$newValue)
    array_push($setArray, " $column = $newValue");
$sql .= implode(',', $setArray);

// WHERE
$sql .= ' WHERE '.implode(' ', $this->db->ar_where);

$this->db->query($sql);
Update and Join query together in codeigniter?

Update and Join query together in codeigniter?


By : Tat Ca Sau
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further @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..
code :
 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;


}
Custom ways to write join, inner join mysql query in codeigniter

Custom ways to write join, inner join mysql query in codeigniter


By : Jaime Leon Nadal
Date : March 29 2020, 07:55 AM
it helps some times I have a query to select data from multiple tables. How do I write its equivalent code in codeigniter. See the query: , You can try the following (i removed the $ sign from staff)
code :
$query = $this->db
    ->select("*")
    ->from("A")
    ->join("B", "A.ad = B.ad_no")
    ->where("B.ad_no in (select ad_no from A where staff!='00:00' and staff!='0:00')",NULL, false)
    ->order_by("B.ctype", "ASC")
    ->order_by("B.cname", "ASC")
    ->order_by("B.ad_no", "ASC")
    ->get();
echo $this->db
    ->select("*")
    ->from("A")
    ->join("B", "A.ad = B.ad_no")
    ->where("B.ad_no in (select ad_no from A where staff!='00:00' and staff!='0:00')",NULL, false)
    ->order_by("B.ctype", "ASC")
    ->order_by("B.cname", "ASC")
    ->order_by("B.ad_no", "ASC")
    ->get_compiled_select();
Join and Update in CodeIgniter

Join and Update in CodeIgniter


By : Perumal S
Date : March 29 2020, 07:55 AM
I hope this helps . Is there a specific reason why you store all the information in all tables?
Wouldn't it be easier to store the personal data in the user-table, the data connected to a post in the post-table, and the data of a comment in the comment table?
code :
$this->db->where('user_id', $id);
$this->db->update('users', $data);

$this->db->where('user_id', $id);
$this->db->update('posts', $data);

$this->db->where('user_id', $id);
$this->db->update('comments', $data);
How update a table in codeigniter with inner join?

How update a table in codeigniter with inner join?


By : David
Date : March 29 2020, 07:55 AM
help you fix your problem You have minute error in your script, you missed alias of slave table
VERSION 1
code :
public function delete_all($id_pris){
   $this->db->join('tbl_family f','p.id_person = f.id_person',"inner"); // you missed `f` here
   $this->db->set('p.active', '0');
   $this->db->where('f.id_prisoners', $id_pris);
   $data_result = $this->db->update('tbl_person p');
   return  $data_result;
}
$this->db->set('p.active', '0');
$this->db->where('f.id_prisoners', $id_pris);
$this->db->where('p.id_person = f.id_person')
$data_result = $this->db->update('tbl_family as f, tbl_person as p');
return $data_result;
$sql = "
UPDATE tbl_person p
INNER JOIN tbl_family_victim f  ON  p.id_person = f.id_person
SET p.active = 0
WHERE f.id_prisoners = $id_pris";
$this->db->query($sql);
$this->db->set('p.active', '0');
$this->db->where('f.id_prisoners', $id_pris);
$data_result = $this->db->update('tbl_family as f JOIN  tbl_person as p ON p.id_person = f.id_person');
return $data_result;
Related Posts Related Posts :
  • Laravel : How to retrieve data from inside an nested array
  • Codeigniter search with comma-separated values
  • upload file on laravel 5.7
  • Wordpress - How to display 10 users only?
  • Display the results in the HTML
  • PHP - mysqli_fetch_assoc, 2 results then into an array
  • mysqli update database receiving email and password reset token
  • PHP mailer not creating new lines
  • IF / OR statement causes Call to undefined function() error. Why?
  • How to read Protocol Buffers delimited I/O functions
  • Creating a link from Google Chart timeline item
  • Rewrite PHP variables from URL with .htaccess
  • Undesired output for php array creation
  • Symfony 4 - custom authentication FosUserBundle
  • laravel: cant push object property to array
  • When sharing on facebook, showing angular brackets in title and decription
  • Undefined function: 7 ERROR: operator does not exist: public.ltree public.< public.ltree[]
  • Generate a CSV in php from Array or Object
  • LibreOffice convert PDF to Word as textbox instead normal document
  • php laravel swift email sending problems
  • Reload PHP file in command line PHP-CLI
  • how do I fetch a certain part out of an database?
  • CodeIgniter URL Route with ID and title
  • Add a header to each column
  • How can I loop stdClass in PHP?
  • Four arrays in for each loop
  • bootstrap 4 cards with php foreach loop
  • Codeigniter return not found on the server
  • PHP Codeigniter Do Upload Function Does Not Work
  • Implement REST API Symfony 3
  • how to add show data button in Yajrabox
  • My WampServer doesnt have apache setting in tray icon
  • Translate checkout fields validation error notices in Woocommerce
  • Embedding nested form type fields in empty symfony form
  • PHP Laravel orderby not working if using `count`
  • Laravel 5.7 my model from my parameter return's empty when i dump it
  • How to pass input value as array instead of passing only one value where array_walk is used in PHP?
  • Replace illegal charactes in a text by underscore in PHP
  • PHP / JSON - Return large string result in error
  • Yii2 DI container: registering same class twice, but with different constructor parameters
  • Creating Subdirectories with a for loop
  • Wordpress get most popular posts in current post category
  • Replace linebreak in specific piece of text in file
  • Update database that has same key with using a new different values
  • Problems with Curl in Discord Oauth2
  • How to remove all lines in file till a specific word occures PHP
  • PHP DOMDocument: may a text node be reused?
  • How to read Armenian texts from Laravel MSSQL database
  • How to view image and pdf files preview in yii2 kartik multiple file upload in update form
  • Which one is best and faster method ?(making drop down method)
  • Using preg_match to get content between tags
  • Laravel 5.7 Eloquent
  • How to combine array inside foreach loop
  • Wordpress-Stripe Integration: Fatal error: Uncaught Error: Class 'Stripe' not found
  • Redirect user to original url from age verification
  • How to update only one input in Laravel form?
  • How to add language translation in JSON file in prestashop
  • Interface 'Monolog\ResettableInterface' not found when running a new project
  • Adding strings when using echo in foreach PHP
  • do-while loop only runs once
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org