Labels

php (35) javascript (31) phpjavascript (30) jquery (23) html (20) mysql (14) database (9) codeigniter (4) json (4) bar chart (2) calendar (2) column chart (2) framework (2) google maps (2) query (2) tables (2) url (2) dropdown (1)

Monday, February 5, 2018

How to delete data in a table using CodeIgniter?

This block of code of will explains about how to delete data from table using CodeIgniter.
Which involves mainly three steps.
  1. View
  2. Controller
  3. Model

View
demodata.php
<html>
<head>
    <style>
        .container {
width: 500px;
height: 100px;
padding: 200px;
        }
table, th, td {
border: 1px solid black;
width:500px;
        }
    </style>
</head>
<body class="container">
<table>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Number</th>
        <th>Update</th>
    </tr>

<?php
    foreach ($k->result() as $row) {
echo '<tr>';
echo '<td>' . $row->id . '</td>';
echo '<td>' . $row->name . '</td>';
echo '<td>' . $row->number . '</td>';
echo "<td><a href='updatedemodata?id=$row->id'>Update</a>
        <a href='deletedemodata?id=$row->id'> / Delete</a></td>";
    }
?>

</table>
</body>
</html>

Controller
Welcome.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {
public function deletedemodata(){
if(isset($_GET['id'])) {
if (($_GET['id'] !== '')) {
$id = $_GET['id'];
$this->levels->deletedemodata($id);
            } else {
echo 'error while deleting';
            }
        }
    }
}
?>

Model
level.php
<?php
class Levels extends CI_Model
{
public function deletedemodata($id)
    {
$this->load->database();
$this->db->where('id', $id);
$this->db->delete('demo');
echo 'Data Deleted successfully';
$this->load->helper('url');
        redirect('/welcome/demodata');
    }
}
?>



9 comments:

  1. Led High Bay Lights I actually take care of such information a lot. I'm interested in this specific info for just a while. Appreciate it and also all the best .

    ReplyDelete
  2. Thanks For Sharing This, Very Interesting And Helpful Support Provide By this blog, This was the first news blog. Digital Signature Certificate

    ReplyDelete
  3. Thanks For Sharing This, Very Interesting And Helpful Support Provide By this blog, This was the first news blog. Digital Signature Certificate

    ReplyDelete
  4. I highly admire your post. Thanks for sharing such wonderful information, I see your post very often and share them on all social media channels.
    Private detective agency in Mumbai

    ReplyDelete
  5. I assure this would be beneficial for most of the people. Class 2 Digital Signature Certificate

    ReplyDelete
  6. I assure this would be beneficial for most of the people. Class 2 Digital Signature Certificate

    ReplyDelete
  7. I highly admire your post. Thanks for sharing such wonderful information, I see your post very often and share them on all social media channels.
    Digital Signature Certificate in Delhi

    ReplyDelete
  8. Pretty section of content. I just stumbled upon your weblog and in accession capital to assert that I acquire in fact enjoyed account your blog posts. Anyway I’ll be subscribing to your feeds and even I achievement you access consistently rapidly. 21st century skills

    ReplyDelete

More Posts

FOLLOW