Welcome Guest, Not a member yet? Register   Sign In
Pagination still Not Work
#1

[eluser]anyamanggar[/eluser]
Helo Guys, I have trouble, and please help me about pagination

Frontend_model
Code:
<?php

class Frontend_model extends CI_Model {
    
     function __construct()
    {
        parent::__construct();
    }



// menampilkan template untuk di depan
function get_list($limit,$offset)
{
  
   $this->db->order_by('id','desc');
  $query = $this->db->get('template',$limit, $offset);
  return $query->result_array();

}

function get_template()
{
   $this->db->order_by('id','desc');
  $query = $this->db->get_where('template');
  return $query->result_array();

}

function get_template_kategori($limit,$offset)
{
$kategori_id = $this->input->post('kategori');
  $query = $this->db->get_where('template', array('kategori' => $kategori_id), $limit,$offset);
  return $query->result_array();

}

function num_rows_template()
{
  return $this->db->get('template')->num_rows();
  
}

function num_rows_template_select()
{
  $kategori_id = $this->input->post('kategori');
  return $this->db->get_where('template', array('kategori' => $kategori_id))->num_rows();
  
}

// ini end of class model
}

home(controller)
Code:
<?php

if (!defined('BASEPATH')) exit ('No direct script access allowed');

class Home extends CI_Controller{


public function __construct(){
parent::__construct();
  $this->load->model('frontend_model');
    $this->load->library('form_validation');
  $this->load->helper('form');
  $this->load->helper('url');
  $this->load->library('table');
  $this->load->helper('html');
  $this->load->library('pagination');
}

public function index($offset = 0){
  $limit = 10;
  if(empty($offset)){ $offset = 0;}

$config['first_link'] = 'Kembali Ke Halaman Depan';
$config['first_tag_open'] = '<li class="pagination">';
$config['first_tag_close'] = '</li>';

$config['last_link'] = 'Halaman Terakhir';
$config['last_tag_open'] = '<li class="pagination">';
$config['last_tag_close'] = '</li>';


// Next Link
$config['next_link'] = 'Berikutnya';
$config['next_tag_open'] = '<li class="pagination">';
$config['next_tag_close'] = '</li>';

// Previous Link
$config['prev_link'] = 'Sebelumnya';
$config['prev_tag_open'] = '<li class="pagination">';
$config['prev_tag_close'] = '</li>';

// Current Link
$config['cur_tag_open'] = '<li class="activepagination">';
$config['cur_tag_close'] = '</li>';

// Digit Link
$config['num_tag_open'] = '<li class="pagination">';
$config['num_tag_close'] = '</li>';
  
$data['listtemplate'] = $this->frontend_model->get_list($limit,$offset);
$config['base_url'] = base_url().'/home/index/';
$config['total_rows'] = $this->frontend_model->num_rows_template();
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);



// ini untuk dropdown menu
$data['templatedepan'] = $this->frontend_model->get_template();
  $dbres = $this->db->get('kategori');

  $ddmenu = array();
  foreach ($dbres->result_array() as $tablerow) {
    $ddmenu[$tablerow['nama_kategori']] = $tablerow['nama_kategori'];
  }
  $data['options'] = $ddmenu;
$this->load->view('frontend/home_view', $data);
}


function submit($offset = 0){
  $limit = 10;
  if(empty($offset)){ $offset = 0;}
  
  $config['first_link'] = 'Kembali Ke Halaman Depan';
$config['first_tag_open'] = '<li class="pagination">';
$config['first_tag_close'] = '</li>';

$config['last_link'] = 'Halaman Terakhir';
$config['last_tag_open'] = '<li class="pagination">';
$config['last_tag_close'] = '</li>';


// Next Link
$config['next_link'] = 'Berikutnya';
$config['next_tag_open'] = '<li class="pagination">';
$config['next_tag_close'] = '</li>';

// Previous Link
$config['prev_link'] = 'Sebelumnya';
$config['prev_tag_open'] = '<li class="pagination">';
$config['prev_tag_close'] = '</li>';

// Current Link
$config['cur_tag_open'] = '<li class="activepagination">';
$config['cur_tag_close'] = '</li>';

// Digit Link
$config['num_tag_open'] = '<li class="pagination">';
$config['num_tag_close'] = '</li>';
          
$data['listtemplate'] = $this->frontend_model->get_template_kategori($limit,$offset);
$config['base_url'] = base_url().'/home/submit/';
$config['total_rows'] = $this->frontend_model->num_rows_template_select();
$config['per_page'] = $limit;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);



  $dbres = $this->db->get('kategori');

  $ddmenu = array();
  foreach ($dbres->result_array() as $tablerow) {
    $ddmenu[$tablerow['nama_kategori']] = $tablerow['nama_kategori'];
  }
  $data['options'] = $ddmenu;
$this->load->view('frontend/sub_view', $data);
    
        }

}

view
Code:
<div id="kategori">
<h1 class="titlekategori">Silahkan pilih kategori website yang diinginkan: </h1>
<br /> <br />
   &lt;?php
   echo form_open('home/submit', $options);
   echo form_dropdown('kategori',$options, 'selected = Hotels');
    echo form_submit('mysubmit', 'GO','class = buttonsearch');
?&gt;
</div>

<ul class="listtemp">
&lt;?php
foreach ($listtemplate as $kategoridepan_item): ?&gt;
<li><img src="&lt;?php echo base_url();?&gt;&lt;?php echo $kategoridepan_item['img_path'] ?&gt;" alt="gallery thumbnail" /><br />&lt;?php echo $kategoridepan_item['title'] ?&gt; <br />
  <a href="&lt;?php echo $kategoridepan_item['link'] ?&gt;">Demo</a>

The quistion is, when i click the page didnt show of with true data..
#2

[eluser]Aken[/eluser]
Pagination class only generates HTML links. You need to specify the limit and offset for your DB query manually.
#3

[eluser]anyamanggar[/eluser]
For this page pagination successfully
http://toentas.com/demo/home.html

but when submit clicked, like the example I want to see the travel category, when clicked and paginationnya successfully managed to perform in accordance with the number but when I click on page 2 in pagenation data display does not match the number of templates

http://toentas.com/demo/home/submit.html

is there a bugs? please help me
#4

[eluser]Sanjay Sarvaiya[/eluser]
Use session for selected category and pass where cause in model query.


Code:
if(isset($_post) and $_POST['GO']=='GO') {
    $this->session->unset_userdata('category');
    $this->session->unset_userdata('type') ;
}
  $where ='';
if((isset($_POST) and $_POST['GO'] == 'GO') || @$this->session->userdata('type') == 'cate') {
if(!$this->session->userdata('category'))
  $this->session->userdata('category',$_POST['category'])

$where = "category = $this->session->userdata('category')";

}
$data['listtemplate'] = $this->frontend_model->get_template_kategori($limit,$offset,$where);
$config['base_url'] = base_url().'/home/submit/';
$config['total_rows'] = $this->frontend_model->num_rows_template_select($where);
$config['per_page'] = $limit;

hope that helps
#5

[eluser]anyamanggar[/eluser]
[quote author="Sanjay Sarvaiya" date="1350026554"]Use session for selected category and pass where cause in model query.


Code:
if(isset($_post) and $_POST['GO']=='GO') {
    $this->session->unset_userdata('category');
    $this->session->unset_userdata('type') ;
}
  $where ='';
if((isset($_POST) and $_POST['GO'] == 'GO') || @$this->session->userdata('type') == 'cate') {
if(!$this->session->userdata('category'))
  $this->session->userdata('category',$_POST['category'])

$where = "category = $this->session->userdata('category')";

}
$data['listtemplate'] = $this->frontend_model->get_template_kategori($limit,$offset,$where);
$config['base_url'] = base_url().'/home/submit/';
$config['total_rows'] = $this->frontend_model->num_rows_template_select($where);
$config['per_page'] = $limit;

hope that helps[/quote]

Not work Sanjay.. Sad
#6

[eluser]anyamanggar[/eluser]
Help Me Please Sad
#7

[eluser]anyamanggar[/eluser]
problem fix it. Thanks CI forum, thanks CI developer .. for build this framework




Theme © iAndrew 2016 - Forum software by © MyBB