I am showing the best method to learn of delete query with where condition in Codeigniter.
As well as, explain Codeigniter delete query return value from the database.
Also, given some example code of delete query. when using where condition in the below section.
public function deletedata(){
$this->db->where('id', 2);
$this->db->delete('table_name');
}
Table of Contents
Delete Query with Where Condition in Codeigniter
public function detele_data($id){
$this->db->where('id', $id);
$this->db->delete('user');
}
Here, We displaying a delete function for delete data. which is comes from the database using where condition.
So, $this->db->where() this is function of where condition. Which we used in model class.
After that, added delete query $this->db->delete(‘user’).
In this delete function, the user has a table name. when you want to delete a single row from the database table.
So, you can change the table name and apply this code to your model class.
Thus, you can saw delete queries in the where condition. So, Implements a variable $id.
Because this id passes to dynamic. And then comes from the controller to delete the specific row from a database table.
public function detele_data(){
$arr = array(22, 33, 44 );
$this->db->where('id', $id);
$this->db->delete('user');
}
As an example, all the above code section. It has given an example that shows some value in an array.
So then, it means you can pass an array to delete multiple rows. And getting from the database table using Codeigniter.
This is a database table image there has multiple data stores with the ids as per show Clause.
Codeigniter Delete Query Return Value
public function detele_data(){
$this->db->where('id', $id);
$delete = $this->db->delete('user');
return $delete;
}
Hence, you can see this is a simple query used. and delete query return value with clause.
Firstly, getting a query a variable. and then added return value in this concept in Codeigniter.
Simple Delete in Codeigniter
public function getdata(){
$this->db->query("delete From table_name where id = 2 ");
}
Hence, we apply simple delete query using codeigniter. In this code $this->db->query() added this codeigniter funtion.
Also, put the delete simple query with the where conditions. Codeigniter provide some query in different ways. Therefore we have shown some ways.
Now, we were given an example of code optimization in Codeigniter. in the below section.
public function data(){
$this->db->delete('table_name')
->where('id', 2);
}
Conclusion
Finally, we explain the best ways to learn to delete queries with where conditions in Codeigniter.
If you have any other requirements or issues ask us in comment sections. Also, learn about the main topic of How to use Join Query in Codeigniter