I have a view 'customer_name.php':
<html>
<body>
<?php
foreach($names as $name){
$details = anchor('customer/show_details/'.$name->customer_id, $name->customer_nama);
$link = anchor('customer/delete/'.$name->customer_id, 'HAPUS');
$this->table->add_row($details,$link);
}
echo $this->table->generate();
echo $this->pagination->create_links();
?>
</body>
</html>
a controller 'customer.php':
<?php
defined('BASEPATH') or exit('No direct access allowed');
class Customer extends CI_Controller{
function __construct(){
parent:: __construct();
$this->load->helper(array('form','url','html'));
$this->load->library(array('session','table','pagination'));
$this->load->helper(array('form','url','html'));
$this->load->model('customer_model');
}
function show_name(){
$customer = $_SESSION['name'];
$config['base_url'] = base_url().'customer/show_name/';
$config['total_rows'] = $this->customer_model->get_rows_total();
$config['per_page'] = 5;
$config['uri_segment'] = 3;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="first page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="last page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="previous page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$tmpl = array('table_open' => '<table class="table table-bordered table-striped table-condensed">');
$this->table->set_template($tmpl);
$header = array('Nama', 'Action');
$this->table->set_heading($header);
$offset = ($this->uri->segment(3))? ($this->uri->segment(3)-1)*$config['per_page']:0;
$data['names'] = $this->customer_model->show_name($config['per_page'], $offset);
$this->load->view('customer_name',$data);
}
function show_details($id){
function show_add_form(){
function add(){
$this->show_name();
}
function update(){
function delete($id){
$this->customer_model->delete($id);
$this->show_name();
}
}
and a model 'customer_model.php':
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Customer_model extends CI_Model{
function __construct(){
parent::__construct();
$this->load->database();
}
function get_rows_total(){
return $this->db->count_all('customers');
}
function show_name($limit, $offset){
$this->db->select('customer_id , customer_nama');
return $query = $this->db->get('customers', $limit, $offset)->result();
}
function show_details($id){
function add(){
function update(){
function delete($id){
$this->db->query("DELETE FROM customers WHERE customer_id = '$id'");
}
}
I got a problem when i tried to delete a customer data. The controller delete() should call show_name() and customer_name.php shows the customer data, but it don't. But when i use add(), the customer_name.php shows the customer data. When refresh the page, the data is there. But when i delete a data, it shows nothing.. I don't have any idea why this problem occur.
I appreciate any help from you. Sorry for the long post.