Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a view 'customer_name.php':
HTML
<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
<?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'];
		
		// pagination configuration
		$config['base_url'] = base_url().'customer/show_name/';
		$config['total_rows'] = $this->customer_model->get_rows_total();
		$config['per_page'] = 5; // query per page
		$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);
		
		//table configuration
		$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){//a bunch of code}
	
	function show_add_form(){//a bunch of code}
	
	function add(){
                //a bunch of code
		$this->show_name();
	}
	
	function update(){//a bunch of code}
	
	function delete($id){
		$this->customer_model->delete($id);
		$this->show_name();
	}
	
}

/* End of file Administrator.php */
/* Location : D:\Dropbox\www\order\application\controllers\Administrator.php */


and a model 'customer_model.php':
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){//a bunch of code}
	
	function add(){//a bunch of code}
	
	function update(){//a bunch of code}

	
	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.
Posted
Updated 2-Aug-15 18:17pm
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900