1 00:00:01,570 --> 00:00:02,200 Welcome back. 2 00:00:02,680 --> 00:00:08,980 So now it's time to add another important feature to our website, which is the pagination. 3 00:00:09,370 --> 00:00:10,540 So what is pagination? 4 00:00:10,900 --> 00:00:18,790 Pagination is the process of displaying only a certain number of products in the in the main page and 5 00:00:18,790 --> 00:00:21,640 then adding here about are we already out of this bar? 6 00:00:22,120 --> 00:00:31,450 And that bar will allow users to go to two to click on a button and get more products and different 7 00:00:31,450 --> 00:00:31,900 products. 8 00:00:32,320 --> 00:00:39,430 Because the reason why we need pagination and the reason why so many websites use pagination is because 9 00:00:39,430 --> 00:00:44,170 you cannot display all products in a in a single page. 10 00:00:44,170 --> 00:00:48,100 It's especially if you have a very big e-commerce website. 11 00:00:48,730 --> 00:00:51,310 Imagine you have 1000 products. 12 00:00:51,310 --> 00:00:56,740 It's just impossible to display 1000 products in a single page. 13 00:00:57,100 --> 00:01:03,280 Therefore, you need to you need to have pagination and you need to display you need to allow users 14 00:01:03,280 --> 00:01:07,900 to check out only a certain number of products. 15 00:01:08,200 --> 00:01:14,920 And then if if they want to check out more products, they would have to click on two and then three 16 00:01:14,920 --> 00:01:16,000 and then four, etc.. 17 00:01:16,690 --> 00:01:23,500 This feature is super important and very, very important, especially if you have a very big e-commerce 18 00:01:23,500 --> 00:01:28,390 store and maybe at the beginning maybe you wouldn't want want pagination. 19 00:01:28,690 --> 00:01:34,300 But I promise you, if you grow, if your business grows, you will at some point need attention. 20 00:01:34,570 --> 00:01:41,980 There is no way you could just join a big e-commerce store website without having pagination. 21 00:01:41,980 --> 00:01:43,630 Therefore, pagination is a must. 22 00:01:43,720 --> 00:01:47,620 You you at some point you would have to have pagination. 23 00:01:47,980 --> 00:01:52,450 So let me show you how you can advertise and how you can activate pagination. 24 00:01:52,750 --> 00:01:58,330 We have the here the this bar, but of course it's not working because we need to activate it. 25 00:01:58,990 --> 00:02:04,000 By the way, the process of adding pagination is a little tricky, but I'm going to be I'm going to 26 00:02:04,000 --> 00:02:06,100 try to make it as easy as possible. 27 00:02:06,100 --> 00:02:08,920 And also I'm going to try to make it as fun as possible. 28 00:02:09,580 --> 00:02:15,040 So let me go to my project and start working on pagination. 29 00:02:15,430 --> 00:02:20,080 First of all, pagination will be added to the shop page because this is the shop page. 30 00:02:21,070 --> 00:02:25,330 So in the shop page, remember at the top we have a statement. 31 00:02:25,810 --> 00:02:34,660 This statement will will be executed in case in case user wants to search for a specific product or 32 00:02:35,200 --> 00:02:38,890 in case the user wants to filter filter products. 33 00:02:38,890 --> 00:02:48,010 So for example, if a user wants only choose goods or watches and if user wants are products that are 34 00:02:48,010 --> 00:02:56,020 under a certain amount of money, then they would have to click on search at first select or simply 35 00:02:56,020 --> 00:02:58,240 criteria and then click on search. 36 00:02:59,230 --> 00:03:02,020 Else we will get all products. 37 00:03:02,020 --> 00:03:03,130 And this is not correct. 38 00:03:03,550 --> 00:03:04,960 This is correct if. 39 00:03:04,990 --> 00:03:06,250 Only if your. 40 00:03:06,940 --> 00:03:09,790 If you have small. 41 00:03:11,510 --> 00:03:12,140 Business. 42 00:03:13,070 --> 00:03:15,590 Small websites. 43 00:03:16,250 --> 00:03:24,230 But if you have, say, 1000 products or more, it would be very difficult to just continue and display 44 00:03:24,230 --> 00:03:26,570 all of the products here if you are not going to work. 45 00:03:27,290 --> 00:03:30,080 So let's now start working on pagination. 46 00:03:30,470 --> 00:03:32,060 So here we are pagination. 47 00:03:32,060 --> 00:03:38,210 And instead of getting all products, we need to remove this code and instead we need to start working 48 00:03:38,210 --> 00:03:38,870 on pagination. 49 00:03:39,380 --> 00:03:45,260 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 50 00:03:45,740 --> 00:03:47,200 paid number of pages. 51 00:03:47,210 --> 00:03:52,040 So we need to say if is set and then get. 52 00:03:53,290 --> 00:03:53,770 Get. 53 00:03:54,950 --> 00:03:56,930 And then page. 54 00:03:58,580 --> 00:03:59,330 Number. 55 00:04:00,660 --> 00:04:01,380 And. 56 00:04:02,520 --> 00:04:03,150 And. 57 00:04:06,220 --> 00:04:06,910 Get. 58 00:04:10,970 --> 00:04:11,570 Get. 59 00:04:13,600 --> 00:04:15,940 Our page number page. 60 00:04:18,340 --> 00:04:21,430 Number is not equal to nothing. 61 00:04:31,830 --> 00:04:39,150 Then what we need to do at this point, we need to set the page number. 62 00:04:39,150 --> 00:04:40,470 So we need to say. 63 00:04:40,710 --> 00:04:48,390 If the page number is if the page number is set and it's not it's not zero, then it means that there 64 00:04:48,390 --> 00:04:49,320 is a page number. 65 00:04:49,590 --> 00:04:52,770 It means that the user is at a specific page number. 66 00:04:53,070 --> 00:05:01,470 And at this point, we need to say page number is equal to they get requests because now we know that 67 00:05:01,470 --> 00:05:05,160 this request is has been initialized or was initialized, they should say. 68 00:05:07,450 --> 00:05:16,780 So the page number, this variable page number is why is initialize initialized earlier else if users 69 00:05:16,780 --> 00:05:22,600 just came to this page, if a user came to this page, just came to this page, then we need to set 70 00:05:23,620 --> 00:05:28,180 the page number to be one because the default, this is going to be the default. 71 00:05:28,570 --> 00:05:33,880 So the default if user just came. 72 00:05:35,170 --> 00:05:35,980 Or entered. 73 00:05:37,360 --> 00:05:43,690 The page, then the full page is one. 74 00:05:45,200 --> 00:05:52,130 As one if user if user has already. 75 00:05:53,990 --> 00:05:56,150 Enter page. 76 00:05:56,900 --> 00:05:58,460 Then it me. 77 00:05:58,520 --> 00:06:00,020 Then the page number. 78 00:06:00,830 --> 00:06:02,180 Page number. 79 00:06:03,420 --> 00:06:07,560 Is the one that he selected. 80 00:06:07,930 --> 00:06:10,080 It is the one that they selected. 81 00:06:11,090 --> 00:06:17,700 So because they may they may have clicked on on page two or three or next. 82 00:06:18,410 --> 00:06:20,840 So we need to say the page number is going to be equal to. 83 00:06:21,320 --> 00:06:23,810 Now, after this point, after this card. 84 00:06:24,170 --> 00:06:27,260 What we want to do is that we need to get products from the database. 85 00:06:27,270 --> 00:06:28,610 So this is pretty simple. 86 00:06:28,610 --> 00:06:30,080 We have already done this many times. 87 00:06:30,080 --> 00:06:37,300 I'm going to say statement one is equal to connection and then we need to prepare and get all. 88 00:06:37,320 --> 00:06:38,330 Now we need to get all. 89 00:06:38,930 --> 00:06:41,300 This is very simple and we have already done that. 90 00:06:41,840 --> 00:06:43,760 Select all. 91 00:06:45,320 --> 00:06:49,130 Select not all select counts. 92 00:06:49,460 --> 00:06:51,470 And I'm going to explain why we need to count. 93 00:06:52,190 --> 00:06:53,570 We need to get count. 94 00:06:53,570 --> 00:06:57,560 All count all as. 95 00:06:58,700 --> 00:06:59,360 As. 96 00:07:00,410 --> 00:07:01,190 Total. 97 00:07:02,820 --> 00:07:03,540 Records. 98 00:07:05,220 --> 00:07:05,790 From. 99 00:07:07,890 --> 00:07:08,580 Products. 100 00:07:11,060 --> 00:07:12,100 So what does this mean? 101 00:07:12,110 --> 00:07:14,660 What does this statement mean? 102 00:07:14,870 --> 00:07:19,820 This statement is going to get us the total number of products we have in the database. 103 00:07:20,270 --> 00:07:25,190 So if you have 1000 products, it's going to return that number because you would. 104 00:07:25,310 --> 00:07:35,240 There is no way by which you could count the number of products, especially if you have a very big 105 00:07:35,240 --> 00:07:35,740 website. 106 00:07:35,750 --> 00:07:36,920 You need to use this statement. 107 00:07:36,930 --> 00:07:43,610 This is going to return the number of products. 108 00:07:44,650 --> 00:07:47,530 So you could have 1000 products. 109 00:07:48,250 --> 00:07:49,780 10,000 products, it depends. 110 00:07:50,980 --> 00:07:54,760 Then what we need to do is that we need to exclude the statement. 111 00:07:55,240 --> 00:07:56,440 It's the empty one. 112 00:07:59,180 --> 00:07:59,900 Excuse. 113 00:08:01,350 --> 00:08:04,910 And then we need to bind the results. 114 00:08:04,920 --> 00:08:13,650 We need to get the we need to say statement one and then bind the result and restore the result in a 115 00:08:13,650 --> 00:08:20,100 variable called total recall, total recall, three cords. 116 00:08:20,520 --> 00:08:24,960 So this total records is going to represent the number of products. 117 00:08:25,980 --> 00:08:29,130 Then what we want to do is that we want to store the results. 118 00:08:29,130 --> 00:08:33,290 So I'm going to say statement one store result. 119 00:08:34,110 --> 00:08:35,700 Lastly, I'm going to say fetch. 120 00:08:37,070 --> 00:08:38,480 Is the empty one. 121 00:08:39,460 --> 00:08:41,020 And then fetch. 122 00:08:42,600 --> 00:08:47,940 Let me just remove the space because the code is going to get longer. 123 00:08:47,940 --> 00:08:51,350 And I don't want to I want I don't want to confuse you. 124 00:08:51,450 --> 00:08:54,350 So the first step is to determine here. 125 00:08:54,360 --> 00:08:57,900 The first step is to determine. 126 00:08:59,090 --> 00:09:00,740 Which number? 127 00:09:01,400 --> 00:09:03,920 The second step is to return the number of products. 128 00:09:05,330 --> 00:09:14,420 The third step is to is to set the total number of products that you want to display per page. 129 00:09:14,870 --> 00:09:19,850 So here we we get we got all of the products, but of course, we don't want that. 130 00:09:19,880 --> 00:09:24,410 Instead, we need to determine a specific number of products to display per page. 131 00:09:24,890 --> 00:09:28,720 For example, you can display eight products per page, ten products per page. 132 00:09:28,730 --> 00:09:31,310 It depends upon how many you want to display. 133 00:09:31,580 --> 00:09:37,040 But my recommendation is not to display more than 20 to 30 products. 134 00:09:37,280 --> 00:09:40,970 Maximum you would you wouldn't want to display too many products. 135 00:09:41,510 --> 00:09:44,240 So in my case, I'm going to test with eight products. 136 00:09:44,480 --> 00:09:49,310 So I'm going to say here, I'm going to add a comment and then I'm going to say products. 137 00:09:50,280 --> 00:09:50,860 Vero Beach.