delete Query In Codeigniter Example Tutorial

Today, We want to share with you delete Query In Codeigniter Example Tutorial.In this post we will show you insert query in codeigniter, hear for codeigniter join query we will give you demo and example for implement.In this post, we will learn about Join Query In Codeigniter with an example.

delete Query In Codeigniter Example Tutorial

There are the Following The simple About delete query in codeigniter Full Information With Example and source code.

Another must read:  Codeigniter delete query from Database

As I will cover this Post with live Working example to develop join query in codeigniter, so the join in codeigniter is used for this example is following below.

Codeigniter delete database record

codeigniter Delete method is used to remove/delete the one or more records data from MySQL database table. If We need to delete all the MySQL data from a Databse table, We can simple use the truncate() function, or onther methods like as a empty_table().

delete query in codeigniter
delete query in codeigniter
  • $this->db->delete()
  • $this->db->empty_table()
  • $this->db->truncate()
  • Delete With Join

$this->db->delete()

$this->db->delete('tbl_client', array('member_id' => $member_id)); 
//DELETE FROM tbl_client WHERE member_id = $member_id

$this->db->where('member_id', $member_id);
$this->db->delete('tbl_client');
//DELETE FROM tbl_client WHERE member_id = $member_id

simple pass An array of Dataabse table names can be argument passed into delete() function if you would like to simple database table to delete data from multiple table.

Another must read:  codeigniter print last query - PHP Examples

$member_id=5;
$tables = array('member', 'team', 'category');
$this->db->where('member_id', $member_id);
$this->db->delete($tables);

$this->db->empty_table()

List of all Google Adsense, VueJS, AngularJS, PHP, Laravel Examples.

$this->db->empty_table('tbl_client'); 
// DELETE FROM tbl_client

$this->db->truncate()

$this->db->from('tbl_client'); 
$this->db->truncate(); 
(OR)
$this->db->truncate('tbl_client'); 
// TRUNCATE table tbl_client;

Delete With Join

$this->db->from("member");
$this->db->join("team", "member.t1_member_id = team.t2_member_id");
$this->db->where("team.t2_member_id", $member_id);
$this->db->delete("member");

Example 1: Codeigniter delete database record

Controller

<?php
class Pakainfo extends CI_Controller 
{
	public function __construct()
	{
	parent::__construct();
	$this->load->database();
	$this->load->helper('url');
	$this->load->model('Pakainfo_Model');
	}

	public function savedata()
	{
		$this->load->view('registration');
		if($this->input->post('save'))
		{
			$n=$this->input->post('name');
			$e=$this->input->post('email');
			$m=$this->input->post('phone');
			$this->Pakainfo_Model->saverecords($n,$e,$m);		
			redirect("Pakainfo/dispdata");  
		}
	}
	
	public function dispdata()
	{
		$result['data']=$this->Pakainfo_Model->displayrecords();
		$this->load->view('display_records',$result);
	}
	
	public function deletedata()
	{
		$id=$this->input->get('id');
		$this->Pakainfo_Model->deleterecords($id);
		redirect("Pakainfo/dispdata");
	}
}
?>

View

<!DOCTYPE html>
<html>
<head>
<title>Display 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>client Name</th>
    <th>client Email</th>
    <th>client Phone</th>
	<th>client Delete</th>
  </tr>
  <?php
  $i=1;
  foreach($data as $client)
  {
  echo "<tr>";
  echo "<td>".$i."</td>";
  echo "<td>".$client->name."</td>";
  echo "<td>".$client->email."</td>";
  echo "<td>".$client->phone."</td>";
  echo "<td><a href='deletedata?id=".$client->client_id."'>Delete</a></td>";
  echo "</tr>";
  $i++;
  }
   ?>
</table>
</body>
</html>

Model

<?php
class Pakainfo_Model extends CI_Model 
{
	function saverecords($name,$email,$phone)
	{
		$query="insert into clients values('','$name','$email','$phone')";
		$this->db->query($query);
	}
	
	function displayrecords()
	{
		$query=$this->db->query("select * from clients");
		return $query->result();
	}
	
	function deleterecords($id)
	{
		$this->db->query("delete  from clients where client_id='".$id."'");
	}	
}
?>

Codeigniter (CRUD) Select Insert Update Delete Query

  1. Update Query In Codeigniter
  2. Select Query In Codeigniter
  3. Insert Query In Codeigniter
  4. Delete Query In Codeigniter
Another must read:  Update Query In Codeigniter Example Tutorial
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 select query in codeigniter.
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.

Leave a Reply

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