CodeIgniter Forums
Pagination issue - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Pagination issue (/showthread.php?tid=71153)



Pagination issue - barrypoore - 07-12-2018

Hi have finally got pagination working (kind of) but cannot resolve two issues:
  • First link isn't actually a link its just a strong tag so you can never get back to the first page, even if you proceed clicking through the links it doesn't become active:

    <ul class="pagination">
    <strong>1</strong>
    <a href="http://codeigniter.local/jobs/12" data-ci-pagination-page="2">2</a>


  • The last link '>' always links to the second link as above, http://codeigniter.local/jobs/12
My controller class is as follows:
        $config["base_url"] = base_url() . "jobs";
        $config["total_rows"] = $this->jobs_model->record_count(); // returns the amount of rows
        $config["per_page"] = 12;
        $config["uri_segment"] = 2;
        $choice = $config["total_rows"] / $config["per_page"];
        $config["num_links"] = round($choice);

Maybe the tutorial I followed has led me up the garden path a bit, I did try and find one in the codeigniter documentation but could only find how to generate the pagination links but it didn't include how to integrate it into my queries so I ended up with pagination links but 500 records on one page.

If anyone could assist or point me to a decent tutorial it would be much appreciated.

I don't really know what else to post, the other functions are straight forward queries, I'm guessing the issue is in the config above. If I remove the last two then 'Last >' is appended to the end and has the correct link url.

I followed this tutorial:
https://www.sitepoint.com/pagination-with-codeigniter/


RE: Pagination issue - php_rocs - 07-12-2018

@barrypoore,

Did you try to see if you could use the CI pagination feature first ( https://codeigniter.com/user_guide/libraries/pagination.html?highlight=pagination )?


RE: Pagination issue - ciadmin - 07-12-2018

The sitepoint tutorial is for CodeIgniter 2. There have probably been some changes for version 3 Undecided
php_rocs advice is reasonable Smile


RE: Pagination issue - barrypoore - 07-13-2018

(07-12-2018, 04:47 PM)ciadmin Wrote: The sitepoint tutorial is for CodeIgniter 2. There have probably been some changes for version 3 Undecided
php_rocs advice is reasonable Smile

Yes I realise now that tutorial is dated, I found another one and have it all working now, it has one more method then I was hoping for but it seems to work, I'll check out that php_rocs, cheers.

Used this one now:
https://code.tutsplus.com/tutorials/pagination-in-codeigniter-the-complete-guide--cms-29030