I don't know how to do a edit and delete function in codeigniter.. I really need it for the admin side of my system.. I really need help.. I want to delete the id in my table named user_acc and edit the whole column
Model:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mod_admin extends CI_Model{
function __construct()
{
parent::__construct();
}
public function user_acc(){
$this->db->select('*');
$this->db->from('user_acc');
$query = $this->db->get();
return $query->result();
}
public function delete()
{
$this->db->where('id');
$this->db->delete();
}
}
Admin:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Admin extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper('url');
$this->load->Model('Mod_admin');
}
public function manageuser(){
$this->load->view('template/adminhead');
$data['user_acc'] = $this->Mod_admin->user_acc();
$this->load->view('manageuser', $data);
}
public function delete_product() {
$this->Mod_admin->delete();
$this->session->set_flashdata('message', '<p>Product were successfully deleted!</p>');
redirect('manageuser');
}
}
View:
<html>
<title>Manage User</title>
<body>
<style>
.shit{
border: 1px solid;
border-collapse: collapse;
}
.shit td{
border: 1px solid;
border-collapse: collapse;
padding: 7px;
}
.shit td tr{
border: 1px solid;
}
.shit td th{
border: 1px solid;
}
</style>
<div id="container">
<table class="shit">
<tr>
<th><strong>ID</strong></th>
<th><strong>Firstname</strong></th>
<th><strong>Lastname</strong></th>
<th><strong>Username</strong></th>
<th><strong>Password</strong></th>
<th><strong>E-mail</strong></th>
<th><strong>Contact</strong></th>
<th><strong>Edit</strong></th>
<th><strong>Delete</strong></th>
</tr>
<?php
foreach($user_acc as $row){
echo
'<tr>
<td>'.$row->id.'</td>
<td>'.$row->firstname.'</td>
<td>'.$row->lastname.'</td>
<td>'.$row->username.'</td>
<td>'.$row->password.'</td>
<td>'.$row->email.'</td>
<td>'.$row->contact.'</td>
<td>'.'<a href="#">'.'Edit</a>'.'</td>
<td>'.'<a href="#">'.'Delete</a>'.'</td>
</tr>';
}
?>
</table>
</div>
</body>
</html>]
How View looks like Please help me to edit and delete users thanks
For updating
In controller :
$result = array( 'column1'=>$val1,'column2'=>$val2,'column3'=>$val3);
$this->model_name->updateEvent( $id , $result );
In model:
public function updateEvent($id, $result){
$this->db->where('db_table_column', $id);
$this->db->update('table_name', $result);
}
For deleting
In controller:
$this->model_name->deleteEvent( $id );
In model:
public function deleteEvent( $id )
{
$this->db->where('db_table_column', $id);
$this->db->delete('table_name');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.