Controller:
Create Test_controller.php inside your controller folder
class Test_controller extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->model('test_model');
}
function del_user($id)
{
$this->test_model->del_users($id);
redirect('test_controller/index', 'refresh');//After delete it will redirect to current page
}
}
----------------------------------------------------------------------------------------------------------
Model:
Create Test_model.php inside your model folder
class Test_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function del_users($id)
{
$this->db->delete('admin_users', array('sno' => $id));
}
}
-----------------------------------------------------------------------------------------------
View:
Create test.php inside your view folder
<table width="200" border="1">
<tr>
<th>Sno</th>
<th>Name</th>
<th>Email</th>
</tr>
<?php foreach($result as $row){ ?>
<tr>
<td><?php echo $row->sno; ?></td>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->email; ?></td>
<td><a href="<?php echo base_url(); ?>index.php/test_controller/del_user/<?php echo $id=$row->sno; ?>">delete</a></td>
</tr>
<?php } ?>
</table>
Create Test_controller.php inside your controller folder
class Test_controller extends CI_Controller
{
public function __construct() {
parent::__construct();
$this->load->model('test_model');
}
function del_user($id)
{
$this->test_model->del_users($id);
redirect('test_controller/index', 'refresh');//After delete it will redirect to current page
}
}
----------------------------------------------------------------------------------------------------------
Model:
Create Test_model.php inside your model folder
class Test_model extends CI_Model {
function __construct()
{
// Call the Model constructor
parent::__construct();
}
function del_users($id)
{
$this->db->delete('admin_users', array('sno' => $id));
}
}
-----------------------------------------------------------------------------------------------
View:
Create test.php inside your view folder
<table width="200" border="1">
<tr>
<th>Sno</th>
<th>Name</th>
<th>Email</th>
</tr>
<?php foreach($result as $row){ ?>
<tr>
<td><?php echo $row->sno; ?></td>
<td><?php echo $row->name; ?></td>
<td><?php echo $row->email; ?></td>
<td><a href="<?php echo base_url(); ?>index.php/test_controller/del_user/<?php echo $id=$row->sno; ?>">delete</a></td>
</tr>
<?php } ?>
</table>
04:01
Share:
0 comments: