Today, We want to share with you Update Query In Codeigniter Example Tutorial.In this post we will show you insert query in codeigniter, hear for select query in codeigniter we will give you demo and example for implement.In this post, we will learn about Select Query In Codeigniter Example Tutorial with an example.
Update Query In Codeigniter Example Tutorial
There are the Following The simple About Codeigniter Active Record: Insert, Select, Update, Delete Full Information With Example and source code.
As I will cover this Post with live Working example to develop delete query in codeigniter, so the join query in codeigniter is used for this example is following below.
PHP Based CodeIgniter Freamworks Like ‘UPDATE’ query statement will run/execute using following methods. They are
In this Example, we will all about how to Update records. I will use docators table to update all the Databse records.
- $this->db->update()
- $this->db->update_string()
- $this->db->update_batch()
Codeigniter (CRUD) Select Insert Update Delete Query
- Update Query In Codeigniter
- Select Query In Codeigniter
- Insert Query In Codeigniter
- Delete Query In Codeigniter
using $this->db->update()
$data = array( 'name' = > $_POST['name'] , 'teamname'= > $_POST['teamname'], 'rate' = > $_POST['rate'] ); $this->db->where('id', $_POST['id']); $this->db->update('tbl_docator', $data);
using $this->db->update_string()
Imp Note: All the Values are automatically restricted escaped, producing safer statements.
$data = array( 'teamname'= >$_POST['teamname'] ); $where = "status = 'docator'"; $str = $this->db->update_string('tbl_docator', $data, $where);
using $this->db->update_batch()
$data = array( array( 'name' = > 'name1' , 'teamname'= > 'teamname1', 'rate' = > 'rate1' ), array( 'name' = > 'name2' , 'teamname'= > 'teamname2', 'rate' = > 'rate2' ) ); $this->db->update_batch('tbl_docator', $data);
Update record CodeIgniter framework PHP
CodeIgniter\application\controllers\Member.php
<?php class Member extends CI_Controller { public function __construct() { parent::__construct(); $this->load->database(); $this->load->model('Member_model'); } public function dispdata() { $result['data']=$this->Hello_model->members_list(); $this->load->view('members_list',$result); } public function updatedata() { $id=$this->input->get('id'); $result['data']=$this->Member_model->displayrecordsById($id); $this->load->view('update_records',$result); if($this->input->post('update')) { $username=$this->input->post('username'); $sirname=$this->input->post('sirname'); $email=$this->input->post('email'); $this->Member_model->update_records($username,$sirname,$email,$id); echo "Date updated successfully !”; } } } ?>
CodeIgniter\application\models\Member_model.php
<?php class Member_model extends CI_Model { function members_list() { $query=$this->db->query("select * from crud"); return $query->result(); } function displayrecordsById($id) { $query=$this->db->query("select * from form where id='".$id.”’”); return $query->result(); } function update_records($username,$sirname,$email,$id) { $query=$this->db->query("update form SET username='$username',sirname='$sirname',email='$email' where id='$id’”); } }
CodeIgniter\application\views\members_list.php
<!DOCTYPE html> <html> <head> <title>Delete records - www.pakainfo.com</title> </head> <body> <table width="600" border="1" cellspacing="5" cellpadding="5"> <tr style="background:#CCC"> <th>Sr No</th> <th>Member First_name</th> <th>Member Last_name</th> <th>Member Email Id</th> <th>Update</th> </tr> <?php $i=1; foreach($data as $member) { echo "<tr>"; echo "<td>".$i."</td>"; echo "<td>".$member->username."</td>"; echo "<td>".$member->sirname."</td>"; echo "<td>".$member->email."</td>"; echo "<td><a href=‘updatedata?id=".$member->id."'>Update</a></td>"; echo "</tr>"; $i++; } ?> </table> </body> </html>
CodeIgniter\application\views\update_records.php
<!DOCTYPE html> <html> <head> <title>Update Member Data</title> </head> <body> <?php $i=1; foreach($data as $member) { ?> <form method="post"> <table width="600" border="1" cellspacing="5" cellpadding="5"> <tr> <td width="230">Enter Your Name </td> <td width="329"><input type="text" name="username" value="<?php echo $member->username; ?>"/></td> </tr> <tr> <td>Enter Your Email </td> <td><input type="text" name="sirname" value="<?php echo $member->sirname; ?>"/></td> </tr> <tr> <td>Enter Your Mobile </td> <td><input type="text" name="email" value="<?php echo $member->email; ?>"/></td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" name="update" value="Update_Records"/></td> </tr> </table> </form> <?php } ?> </body> </html>
Web Programming Tutorials Example with Demo
Read :
Summary
You can also read about AngularJS, ASP.NET, VueJs, PHP.
I hope you get an idea about codeigniter CRUD query.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.