Page 1 of 1

Exploring library package for a beginner programmer?

Posted: Wed Apr 13, 2016 2:31 pm
by bookDig
So I am working on project and I need to apply pagination to it what I am facing is the choice whether I should develop my own code or should I study the pagination library of Laravel I admit the ideal thing would be to first develop it on my own to see how it works but the issue is that I am at a deadline in training period and I have to learn to explore libraries to develop market oriented apps. So would someone kindly recommend me. :|

Re: Exploring library package for a beginner programmer?

Posted: Wed Apr 13, 2016 3:01 pm
by Celauran
I'd do it yourself for the learning experience. Pagination isn't that hard, really. Total items / items per page is your page count. Current page * items per page is your offset. Beyond that it's really just a SELECT statement.

Re: Exploring library package for a beginner programmer?

Posted: Wed Apr 13, 2016 4:40 pm
by Christopher
If it is data in a database, you may need to SELECT COUNT(*) WHERE ... first to get the total records, and then SELECT * WHERE ... LIMIT to get a page worth.

Re: Exploring library package for a beginner programmer?

Posted: Fri Apr 29, 2016 10:34 am
by thinsoldier
Christopher wrote:If it is data in a database, you may need to SELECT COUNT(*) WHERE ... first to get the total records, and then SELECT * WHERE ... LIMIT to get a page worth.
But only if you need to show the total and/or a list of links to go to each page of results. When you have a huge amount of records it might be best to stick to previous and next links and avoid the extra query.

Re: Exploring library package for a beginner programmer?

Posted: Fri Apr 29, 2016 2:30 pm
by Christopher
thinsoldier wrote:But only if you need to show the total and/or a list of links to go to each page of results. When you have a huge amount of records it might be best to stick to previous and next links and avoid the extra query.
This depends on the database. Some databases do not have to scan all records to return a row count. Also, this operation only needs to be performed once when entering the paginated set. Thereafter, it can be passed as a parameter or held in the session.