How to Delete Query with Where Condition in Codeigniter

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');

	}

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.

delete query with where condition in 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

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts

Related Post

How to use Multiple Where Condition in Codeigniter?

Here, we displaying the best method to use multiple where condition in Codeigniter. Also, displaying another method get_where() and multiple where clause in Codeigniter. As well as, given an example fetch data from the database using multiple where condition. likewise, insert, update, and delete. It means all Codeigniter queries with used multiple where clause. Again, […]

Read more

Update Query in Codeigniter using Where Condition

Here, We displayed the best ways to update query in Codeigniter using where condition. Also, given an example of multiple where condition. Similarly, Codeigniter has to provide a simple query to replace data from the MySQL database using a clause. This is update query $this->db->replace(); Thus, I have to show an update function. This function […]

Read more

How to use Join Query in Codeigniter

So, I am going to show you how to use a join query in Codeigniter. Also, retrieve the data as you want with example. Here, we have defined many ways to use join query with where condition. As well as, fetch data multiple methods like left join, right join, full join, and inner join in […]

Read more

x