CodeIgniter Forums
Same Pagination Problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: Same Pagination Problem (/thread-54079.html)



Same Pagination Problem - El Forum - 08-21-2012

[eluser]Önder ÖZCAN[/eluser]
I have pagination problem my model is look like :

class Clinic_list extends CI_Model
{
var $limit;
function __construct()
{
// Call the Model constructor
parent::__construct();
$this->load->database();
$this->load->library('pagination');
}

function entries($limit)

{
$query = $this->db->get('v16_listings',$limit);
return $query->result();
}
}
?>

My Controller is :

<?php
class clinics extends CI_Controller
{
var $data;

public function index ()
{

$this->load->model('Clinic_list');
$this->load->helper(array('form', 'url'));
$config['base_url'] = site_url('clinics/index/page/');
$config['total_rows'] = $this->db->count_all('v16_listings');
$config['per_page'] = 20;
$config['last_link'] = 'Son';
$config['first_link'] = 'İlk';
$this->pagination->initialize($config);
$data['_clinicList'] = $this->Clinic_list->entries (30);
$this->load->view('list', $data);
}
}
?>

In view every pagenumber has same data , its look like this :

http://localhost/saglik/index.php/clinics/index/page/
http://localhost/saglik/index.php/clinics/index/page/20
http://localhost/saglik/index.php/clinics/index/page/40

All page number has no data , i also tried with uri segment but it's better to leave it for CI ?


Same Pagination Problem - El Forum - 08-21-2012

[eluser]Aken[/eluser]
You need to use limit and offset in your query. Right now your code just does the same thing, regardless of what page its on.


Same Pagination Problem - El Forum - 08-21-2012

[eluser]Önder ÖZCAN[/eluser]
$query = $this->db->get(‘v16_listings’,$limit);
return $query->result();

I am using limit in my query , but as i said , when i try with offset it does not work , And is there any live code which is working with ActiveRecord that you can send me the link , Because when i try to search over google i seen only problems about CI Pagination .

Do you all sure that this class working properly ? Because in CI docs. there is no proper example with using Active Record ..


Same Pagination Problem - El Forum - 08-21-2012

[eluser]srpurdy[/eluser]
Add
Code:
$config['uri_segment'] = '3'; //change this to the uri where the page segment would be.

Change
Code:
$data['_clinicList'] = $this->Clinic_list->entries (30);

to that
Code:
$data['_clinicList'] = $this->Clinic_list->entries($config['per_page'],$config['uri_segment']);

entries function

Code:
function entries($limit,$offset)
{
$query = $this->db
->select('*') //you should only select fields you actually need.
->from('v16_listings')
->limit($limit,$offset)
->get();
return $query->result();
}



Same Pagination Problem - El Forum - 08-22-2012

[eluser]Önder ÖZCAN[/eluser]
surpudy , Thank you for your close help .

The sql output looking like this :
In controller:
$config['uri_segment'] = '4';

Sql Output:
SELECT * FROM (`v16_listings`) LIMIT 4, 20

Page Address String :
http://localhost/saglik/index.php/clinics/index/page/40

As you see CI recognize uri segment config as a string , nothing more then variable .... Smile It really funny coz i just didnt make it pagination works regular about more than month, I did all other stuff ( Ajax grid , Models vs ... ) and I also working with Yii but CI pagination ? It really didn't work . And i really And really wonder if they are any live ( working ) Pagination code which using by Active Record ? Because no one has answered about this question Smile

It started to get funny about this ...


Same Pagination Problem - El Forum - 08-22-2012

[eluser]Önder ÖZCAN[/eluser]
I fixed problem :

The solution is , uri_segment is not enough for creating pagination ...

$offset = $this->uri->segment(4,0); is needed for Sql statement which is really gets 4th segment of address string.

When i try to execute everything works fine . But also uri_segment is needed by pagination , it does not do anything but somehow it needed by configuration .

It's just prooved that Pagination Class has a bug !


Same Pagination Problem - El Forum - 08-22-2012

[eluser]srpurdy[/eluser]
[quote author="Önder ÖZCAN" date="1345642597"]I fixed problem :

The solution is , uri_segment is not enough for creating pagination ...

$offset = $this->uri->segment(4,0); is needed for Sql statement which is really gets 4th segment of address string.

When i try to execute everything works fine . But also uri_segment is needed by pagination , it does not do anything but somehow it needed by configuration .

It's just prooved that Pagination Class has a bug ![/quote]

It's not a bug. My mistake. I forgot you can't use that config variable. You can just pass $this->uri->segment(4) instead. Smile I used pagination all the time. Smile

The reason it's needed is the default is 3 I think. So if your using anything other than 3. it's needed. cause you need to tell it to use segment 4 or 5 or whatever. I suspose it could probably be coded better to be smart enough to figure out the segment based on the url config option though.


Same Pagination Problem - El Forum - 08-22-2012

[eluser]Önder ÖZCAN[/eluser]
srpurdy you are the one of man who helped and worked ! You know that this information does not write on anywhere ? even in Pagination Class documents . CI docs really needs to get update ....


Same Pagination Problem - El Forum - 08-22-2012

[eluser]CroNiX[/eluser]
[quote author="Önder ÖZCAN" date="1345658311"]CI docs really needs to get update ....[/quote]Feel free to contribute to the project on github and correct what you think needs correcting.