Welcome Guest, Not a member yet? Register   Sign In
Pagination help (yep again)
#1

[eluser]kevinprince[/eluser]
This seems to be a runnning theme here.

Basically trying to do a simple pagination of data results.

Ive got it counting number rows, and doing the actual pagniation links, i just cant seem to get actual variables to pass. eg if its /person i just want it to start at 0 if its /25 it starts a 25.

The current solutions just 404's when i click the link and also when i try to echo $start it just comes up blank.

Thanks code below.

Code:
function index()
    {
        ///Load the CI LIbraries we need for this functuon
        $this->load->library('table');
        $this->load->library('pagination');
        
        ///Config for Pagination including getting the total number rows in DB
        $config['base_url'] = 'http://www.vk_server.vk/index.php/person/';        
        $config['total_rows'] = $this->db->count_all('vk_people');;
        $config['per_page'] = '25';
        $this->pagination->initialize($config);
        
        ///Setup the starting point for the query
        
        if (!$this->uri->segment(4)) {$start = 0;} else {$start = $this->uri->segment(4);}
        
        $query = $this->db->query("SELECT sname, fname, address, phone, mobile FROM `vk_people` ORDER BY `sname` ASC LIMIT $start, $config[per_page]");
        
        $this->table->set_heading('Surname', 'First Name', 'Address', 'Phone', 'Mobile');
#2

[eluser]chobo[/eluser]
Try setting the "segment" config option (it's segment something, or vice versa Smile ), just look in the user guide or browse the class file.
#3

[eluser]kevinprince[/eluser]
I had a look at the class file it had the values preset?

Ive changed code to below but i still get 404's when i click through.


Code:
function index()
    {
        ///Load the CI LIbraries we need for this functuon
        $this->load->library('table');
        $this->load->library('pagination');
        
        ///Config for Pagination including getting the total number rows in DB
        $config['base_url'] = 'http://www.vk_server.vk/index.php/person/';        
        $config['total_rows'] = $this->db->count_all('vk_people');;
        $config['per_page'] = '25';
        $config['uri_segment'] = '3';
        $config['num_links'] = '2';
        
        $this->pagination->initialize($config);
        
        $query = $this->db->query("SELECT sname, fname, address, phone, mobile FROM `vk_people` ORDER BY `sname` ASC LIMIT $config[uri_segment], $config[per_page]");
#4

[eluser]chobo[/eluser]
It looks right, the only thing I would remove is the index.php file with the .htaccess file. Right now I think you are counting the index.php as a uri segment (I'm not sure if that counts towards it). Once you have that setup change your uri_segment to 2, and your base url (without the index.php), see if that works.
#5

[eluser]kevinprince[/eluser]
Funnily enough reason im still using index.php is because I cant seem to get any one of the numerous soultions working :/
#6

[eluser]chobo[/eluser]
Create an .htaccess file and cut and paste this in there. If it doesn't work, your .htaccess file isn't setup right. Make sure it shows (.htaccess) as the file extension in explorer.

Code:
# For Codeigniter and other php settings
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
#7

[eluser]@li[/eluser]
What does the pagination URL to this page look like? Is it:

http://site.com/controller/25
or:
http://site.com/controler/function/25

If its the first one, then you may have to add a route to your config/routes.php file. Because with
controller/25, it looks for a function '25' in the controller, and since nothing is found it gives a
404 error.

Edit:
Just saw this:

Code:
$config['base_url'] = 'http://www.vk_server.vk/index.php/person/';


If 'person' is a controller, then you do need to add a route like this:


Code:
$route['person/:num']='person/index';


For a URL such as www.site.com/person/24 to work.
#8

[eluser]kevinprince[/eluser]
While this all makes sense.

If i go to www.vk_server.vk/person I still get 404 and theres an index for the controller so it makes no sense.

mod_Rewrite is definetly running fine on my local server as I have a wordpress install working fine, so thats not to blame.

What am I missing as this is really annoying me now !
#9

[eluser]chobo[/eluser]
Do you get that 404 error if you add the index.php to the the url?
#10

[eluser]kevinprince[/eluser]
its alright when i take out all the .htaccess stuff yeah Wink

But obvious id like tidy url's Sad

Any help would be great sorting that out.




Theme © iAndrew 2016 - Forum software by © MyBB