1 00:00:00,570 --> 00:00:03,460 We have all the variables set for pagination. 2 00:00:03,460 --> 00:00:05,600 So let's start adding our limits. 3 00:00:05,600 --> 00:00:09,660 We're going to be limiting the number of items we show on each page. 4 00:00:09,660 --> 00:00:12,860 So we want to add the limits to our catalog calls. 5 00:00:12,860 --> 00:00:17,460 This will tell the database to only return a limited number of items. 6 00:00:17,460 --> 00:00:20,900 Again, reducing the amount of data the page has to handle. 7 00:00:22,020 --> 00:00:23,310 Let's go into our functions page. 8 00:00:25,020 --> 00:00:28,130 In our catalog array we'll need to pass some optional arguments again. 9 00:00:29,350 --> 00:00:33,876 We'll do this with limit = null and 10 00:00:33,876 --> 00:00:37,570 offset = 0. 11 00:00:37,570 --> 00:00:40,980 Remember by giving a parameter a default value 12 00:00:40,980 --> 00:00:44,190 we do not require that the argument be passed. 13 00:00:44,190 --> 00:00:48,250 If we were to call the function full catalog array without passing these 14 00:00:48,250 --> 00:00:53,110 arguments, we would not have a limit and our offset would be set to 0. 15 00:00:53,110 --> 00:00:58,080 By setting the offset default to 0, we can then pass a limit without an offset. 16 00:00:58,080 --> 00:01:00,330 And it would start at the very first item. 17 00:01:01,520 --> 00:01:05,900 If we don't have a limit, we should return all the items in our catalogue. 18 00:01:05,900 --> 00:01:08,360 We'll need to add these limits to our SQL statement. 19 00:01:08,360 --> 00:01:11,343 So let's move our current query into a SQL variable. 20 00:01:20,630 --> 00:01:24,204 We'll then change our method to prepare and add an execute. 21 00:01:30,350 --> 00:01:34,348 We haven't changed any functionality yet, but now we can use a conditional and 22 00:01:34,348 --> 00:01:35,660 add our limits. 23 00:01:35,660 --> 00:01:38,740 We could use MP again here, but let's be a little more specific. 24 00:01:40,380 --> 00:01:46,390 We'll use a new built in function called is_, And we'll pass our limit. 25 00:01:47,800 --> 00:01:50,380 We're going to add a limit, so let's duplicate this line. 26 00:01:52,400 --> 00:01:53,904 We use this line in our else-statement. 27 00:01:58,818 --> 00:02:01,450 And we'll leave our execute outside. 28 00:02:01,450 --> 00:02:03,818 Let's go back up and at our limit with placeholders. 29 00:02:11,728 --> 00:02:17,883 Limit tells us how many items we want to return and offset tells us where to start. 30 00:02:29,991 --> 00:02:36,433 We'll use our PDO::PARAM_INT to filter for an integer. 31 00:02:50,743 --> 00:02:53,180 And the same thing for our offset. 32 00:02:53,180 --> 00:02:57,710 We need to make these changes to our category catalog array function as well. 33 00:02:57,710 --> 00:03:01,702 We'll start by adding our optional parameters, limit and offset. 34 00:03:07,680 --> 00:03:10,934 Again, we'll move our SQL statement out of our prepare. 35 00:03:26,206 --> 00:03:27,924 And then we can add to it. 36 00:03:27,924 --> 00:03:31,273 Let's copy the if statement from our full catalog and paste it here. 37 00:03:42,470 --> 00:03:45,642 We need to change our bind params a little because this statement already 38 00:03:45,642 --> 00:03:46,428 has a parameter. 39 00:03:51,731 --> 00:03:53,535 We'll copy this line for 1. 40 00:03:55,080 --> 00:03:58,421 And then we'll change these to 2 and 3. 41 00:03:58,421 --> 00:04:02,920 We close out our else before the execute, so both of these will get executed. 42 00:04:02,920 --> 00:04:05,200 Great, our functions are now set up. 43 00:04:05,200 --> 00:04:07,900 So we need to pass in the limit and the offset. 44 00:04:07,900 --> 00:04:09,640 Let's go back to the catalog.php page. 45 00:04:10,790 --> 00:04:13,219 Let's scroll down to where we're sending our catalog variables. 46 00:04:16,705 --> 00:04:22,500 We'll pass in the items per page which is our limit, and our offset. 47 00:04:23,970 --> 00:04:26,574 Will also add this to our category catalog array. 48 00:04:38,938 --> 00:04:42,374 Now, let's go back to our browser and refresh our full catalog page. 49 00:04:45,730 --> 00:04:47,160 Perfect. 50 00:04:47,160 --> 00:04:48,000 Well except for 51 00:04:48,000 --> 00:04:51,480 the fact that we can't see any more than eight items yet, let's fix that.