In order to be able to not show a next link on the last page of records we need to know the total number
of pages.
If we have a total of 18 rijkaard for example then the number of pages will be this total divided by
the number of records per page.
Let's dump this value out to see what its value is.
With four rijkaard per page and a total of 18 this value is four point five off four and a half pages.
The page number is always an integer though.
So let's round this value up to the nearest whole number using the sealing function.
Now although this is still a float value it's been rounded up to five pages.
So we can remove this far don't line.
And if the page is less than the total number of pages we set the next property as before if not the
next property will remain NULL.
Then in the index page if the next property isn't NULL we'll display the link.
Otherwise we'll just display the Word next.
So now if we're on the penultimate page and we click next to get to the last page the next link is no
longer there.
Now this works.
We can get rid of this hard coded value for the total number of records.
First let's pass this in as an argument instead
and we can remove the hard coded value here
then in the index page we can pass the total in.
When we create a new paginate object.
We still don't want this to be hard coded though.
We want to count the total number of records in the database.
So let's add a method to the article class to do just that.
We'll call the method get total.
In esky well to count the number of records in a table we use the count function.
We don't need a prepared statement for this so we can just use the query method.
The results of this esky well will be a single column that contains the count of the number of articles
cards.
The query method returns a p the yayo statement object and we can call the fetch column method on this
to get the contents of this single column.
So let's call that method and return the value directly.
Lastly let's add a p p doc comment to this method like that.
Then in the index page we can replace this hard coded number with a call to the new method.
So now on the last page of Ricardos there's automatically no next link based on the number of records
in the database.