[eluser]dinda[/eluser]
I am a beginner and i currently having problem with paging and the result.
and then the searching is works, but paging is not.
Help me please...
This is my code:
Code:
/* controller : */
class Test extends Controller {
function test()
{
parent::Controller();
$this->load->helper('url');
$this->load->helper('form');
$this->load->model("test_model");
$this->load->library('pagination');
$this->load->database();
}
function index()
{
/* Parameter Search Field */
$data['keyword'] = false ;
$this->test_model->keywordsearch = false;
/*load pagination class */
$config['uri_segment'] = 4;
$config['base_url'] = base_url().'index.php/test/index/';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$config['per_page'] = '2';
$config['total_rows'] = $this->db->count_all('ms_user');
$this->pagination->initialize($config);
/* Model Process */
$data['queryuser'] = $this->test_model->search_test_data($config['per_page'],$this->uri->segment(3));
/* View Passing */
$this->load->library('table');
$this->table->set_heading('ID', 'Name');
/* Show Output */
$this->load->view("test_list_v", $data);
}
function search_test()
{
/* Parameter Search Field */
$data['keyword'] = $this->input->post('keyword');
$this->test_model->keywordsearch = $this->input->post('keyword');
/*load pagination class */
$config['uri_segment'] = 4;
$config['base_url'] = base_url().'index.php/test/index/'. $this->uri->segment(3);
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$config['per_page'] = '2';
$config['total_rows'] = $this->db->count_all('ms_user');
$this->pagination->initialize($config);
$offset = (int)$this->uri->segment(4);
/* Model Process */
$data['queryuser'] = $this->test_model->search_test_data($config['per_page'], $offset);
/* View Passing */
$this->load->library('table');
$this->table->set_heading('ID', 'Name');
/* Show Output */
$this->load->view("test_list_v", $data);
}
}
Code:
/* model : */
function search_test_data($num, $offset = false )
{
$this->db->select('userid,username');
$this->db->from('ms_user');
if ($this->keywordsearch) {
$this->db->like("username", $this->keywordsearch);
}
if ($offset)
{
$this->db->limit($num,$offset);
}
else
{
$this->db->limit($num);
}
$this->db->order_by('userid');
$query = $this->db->get();
return $query;
}
Code:
<!-- View -->
<form name="user_find" id="user_find" method="POST" action="<?=site_url('test/search_test')?>">
Cari Nama User :
<input type='text' name='keyword' id='keyword' value='<?= $keyword; ?>' />
<input type="submit" name="Submit" value="Find">
</form>
echo $this->table->generate();
echo $this->pagination->create_links();