Welcome Guest, Not a member yet? Register   Sign In
Pagination automated
#11

[eluser]JoostV[/eluser]
Hi Dine,

First off, this lib is intended for use with default CI URI's, that is: not including a query string (like ?keywords=&search_type=all), so you should expect to find some problems there.

Having said that, I think the problem here is that you switch between manual sql and active record in your queries. I'm not sure if that is at all possible. I think not. This is probably why limit is not in your query.
Code:
$query = "select SQL_CALC_FOUND_ROWS * from tbl_users where 1=1 ";
// (...)
$this->db->limit($config['per_page'], $this->pagination->offset);
$sql = $this->db->query($query);

Try to write the entire query in active record format, for instance
Code:
// Set up SQL
$this->db->where("(name LIKE '%mike%' OR address LIKE '%mike%')");
$this->db->limit($config['per_page'], $this->pagination->offset);
$query = $this->db->get('tbl_users');
// Fetch results
$result = $query->num_rows() > 0 ? query->result_array() : array();
#12

[eluser]JoostV[/eluser]
A tweaked version of this lib is now in the Wiki.
#13

[eluser]Peter Lachky[/eluser]
Hi JoostV,

thanks for great job! However, I've got one question anyway. The lines 156 and 164 of your library (as it is in wiki) uses
Code:
$CI->config->item('base_url')
to setup a links. My question is why is
Code:
$CI->config->item('index_page')
missing there. It causes problems if I use the index.php index file. When I changed these lines like this
Code:
$this->base_url = $CI->config->item('base_url') . $CI->config->item('index_page') . '/' . substr($CI->uri->uri_string(), 1) . '/' . $this->pagination_selector;
the links become ok. If I do not want to use the index.php index file I'll just remove it from config and that's it.

I hope I'va made my point - correct me if I am wrong.

Thanks a lot!
#14

[eluser]iamjerson[/eluser]
Thanks for this lib it saves my time
#15

[eluser]Unknown[/eluser]
great work, just that i need
#16

[eluser]Unknown[/eluser]
Cool thanks for the help Smile
#17

[eluser]Unknown[/eluser]
Great stuff Wink
thanks
#18

[eluser]seeraw[/eluser]
Hi everyone,
Great!!!
and here is the complete working stuff no need to change any file
Write this code in your controller.

$arr['cnt']=$this->login_model->getAllCastChar();
$this->load->library('pagination');
$config['base_url'] = site_url().'HERE IS YOUR CONTROLLER NAME';
$config['total_rows'] = count($arr['cnt']);
$config['per_page'] = '10';
$config['num_links'] = 4; // IT MAY VARY
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$config['uri_segment'] = '4';
$this->pagination->initialize($config);
$arr['data']=$this->login_model->getAllCastCharAdmin($config['per_page'],$this->uri->segment(4));
$this->load->view('VIEW NAME',$arr);
#19

[eluser]bluehat09[/eluser]
Add in your routes.php

Code:
$route['archives/page/:num'] = "archives/index/page/:num";
$route['archives/page'] = "archives/index";

[quote author="wdm*" date="1223382981"]I get a "page not found" when using the pagination links with my default "archives" controller / index view.

This works:
Code:
http://beta.archiv.local/archives/index/offset/5

These don't work:

Code:
http://beta.archiv.local/offset/5
http://beta.archiv.local/archives/offset/5
[/quote]

Thanks for your work Joost
#20

[eluser]quickshiftin[/eluser]
Very nice contribution!




Theme © iAndrew 2016 - Forum software by © MyBB