Welcome back.
So now it's time to add another important feature to our website, which is the pagination.
So what is pagination?
Pagination is the process of displaying only a certain number of products in the in the main page and
then adding here about are we already out of this bar?
And that bar will allow users to go to two to click on a button and get more products and different
products.
Because the reason why we need pagination and the reason why so many websites use pagination is because
you cannot display all products in a in a single page.
It's especially if you have a very big e-commerce website.
Imagine you have 1000 products.
It's just impossible to display 1000 products in a single page.
Therefore, you need to you need to have pagination and you need to display you need to allow users
to check out only a certain number of products.
And then if if they want to check out more products, they would have to click on two and then three
and then four, etc..
This feature is super important and very, very important, especially if you have a very big e-commerce
store and maybe at the beginning maybe you wouldn't want want pagination.
But I promise you, if you grow, if your business grows, you will at some point need attention.
There is no way you could just join a big e-commerce store website without having pagination.
Therefore, pagination is a must.
You you at some point you would have to have pagination.
So let me show you how you can advertise and how you can activate pagination.
We have the here the this bar, but of course it's not working because we need to activate it.
By the way, the process of adding pagination is a little tricky, but I'm going to be I'm going to
try to make it as easy as possible.
And also I'm going to try to make it as fun as possible.
So let me go to my project and start working on pagination.
First of all, pagination will be added to the shop page because this is the shop page.
So in the shop page, remember at the top we have a statement.
This statement will will be executed in case in case user wants to search for a specific product or
in case the user wants to filter filter products.
So for example, if a user wants only choose goods or watches and if user wants are products that are
under a certain amount of money, then they would have to click on search at first select or simply
criteria and then click on search.
Else we will get all products.
And this is not correct.
This is correct if.
Only if your.
If you have small.
Business.
Small websites.
But if you have, say, 1000 products or more, it would be very difficult to just continue and display
all of the products here if you are not going to work.
So let's now start working on pagination.
So here we are pagination.
And instead of getting all products, we need to remove this code and instead we need to start working
on pagination.
So the first thing that we need to do here and this is else we need to say is and then we need to add
paid number of pages.
So we need to say if is set and then get.
Get.
And then page.
Number.
And.
Get.
Our page number page.
Number is not equal to nothing.
Then what we need to do at this point, we need to set the page number.
So we need to say.
If the page number is if the page number is set and it's not it's not zero, then it means that there
is a page number.
It means that the user is at a specific page number.
And at this point, we need to say page number is equal to they get requests because now we know that
this request is has been initialized or was initialized, they should say.
So the page number, this variable page number is why is initialize initialized earlier else if users
just came to this page, if a user came to this page, just came to this page, then we need to set
the page number to be one because the default, this is going to be the default.
So the default if user just came.
Or entered.
The page, then the full page is one.
As one if user if user has already.
Enter page.
Then it me.
Then the page number.
Page number.
Is the one that he selected.
It is the one that they selected.
So because they may they may have clicked on on page two or three or next.
So we need to say the page number is going to be equal to.
Now, after this point, after this card.
What we want to do is that we need to get products from the database.
So this is pretty simple.
We have already done this many times.
I'm going to say statement one is equal to connection and then we need to prepare and get all.
Now we need to get all.
This is very simple and we have already done that.
Select all.
Select not all select counts.
And I'm going to explain why we need to count.
We need to get count.
All count all as.
As.
Total.
Records.
From.
Products.
So what does this mean?
What does this statement mean?
This statement is going to get us the total number of products we have in the database.
So if you have 1000 products, it's going to return that number because you would.
There is no way by which you could count the number of products, especially if you have a very big
website.
You need to use this statement.
This is going to return the number of products.
So you could have 1000 products.
10,000 products, it depends.
Then what we need to do is that we need to exclude the statement.
It's the empty one.
Excuse.
And then we need to bind the results.
We need to get the we need to say statement one and then bind the result and restore the result in a
variable called total recall, total recall, three cords.
So this total records is going to represent the number of products.
Then what we want to do is that we want to store the results.
So I'm going to say statement one store result.
Lastly, I'm going to say fetch.
Is the empty one.
And then fetch.
Let me just remove the space because the code is going to get longer.
And I don't want to I want I don't want to confuse you.
So the first step is to determine here.
The first step is to determine.
Which number?
The second step is to return the number of products.
The third step is to is to set the total number of products that you want to display per page.
So here we we get we got all of the products, but of course, we don't want that.
Instead, we need to determine a specific number of products to display per page.
For example, you can display eight products per page, ten products per page.
It depends upon how many you want to display.
But my recommendation is not to display more than 20 to 30 products.
Maximum you would you wouldn't want to display too many products.
So in my case, I'm going to test with eight products.
So I'm going to say here, I'm going to add a comment and then I'm going to say products.
Vero Beach.