1 00:00:00,390 --> 00:00:04,060 In the last video we got our search form mostly working. 2 00:00:04,060 --> 00:00:06,830 We just need to handle an empty results list. 3 00:00:06,830 --> 00:00:09,730 When there are no items that match our search term. 4 00:00:09,730 --> 00:00:13,610 We also want them to know when we are on a search results page, 5 00:00:13,610 --> 00:00:15,670 as well as what the search term was. 6 00:00:16,700 --> 00:00:18,250 Let's take a look at the finished results. 7 00:00:19,520 --> 00:00:22,810 If I search for Alina, we'll see the page title 8 00:00:22,810 --> 00:00:27,270 showing that we are on the search page and our search term Alena. 9 00:00:27,270 --> 00:00:31,260 We also see that our search term did not return any results. 10 00:00:31,260 --> 00:00:33,506 Let's add these messages back in work spaces. 11 00:00:33,506 --> 00:00:38,710 Back in catalog.php let's scroll down to the h one header. 12 00:00:42,530 --> 00:00:44,910 We're going to add another conditional. 13 00:00:44,910 --> 00:00:47,820 We can check the same way that we did for the section. 14 00:00:47,820 --> 00:00:50,845 If search is not equal to null. 15 00:00:53,630 --> 00:00:55,884 Then we want to display a different header. 16 00:01:04,464 --> 00:01:07,664 Search results for and our search term. 17 00:01:07,664 --> 00:01:10,483 Since we're displaying user input as output, 18 00:01:10,483 --> 00:01:14,864 let's filter that output with the built in function htmlspecialchars. 19 00:01:22,954 --> 00:01:24,820 Now, let's add quotes around the search term. 20 00:01:26,170 --> 00:01:28,070 We can't just add another double quote, so 21 00:01:28,070 --> 00:01:32,560 we use our escape sequence of slash and then a quote. 22 00:01:32,560 --> 00:01:33,870 Let's also add this to the end. 23 00:01:39,210 --> 00:01:40,426 Now we add the else block, 24 00:01:40,426 --> 00:01:43,648 containing our existing title including the other if-statement. 25 00:01:57,481 --> 00:01:59,000 We have our header changed. 26 00:01:59,000 --> 00:02:02,320 Now let's add a message if there are no search results. 27 00:02:02,320 --> 00:02:06,260 After closing the H1 tag we're going to create another conditional. 28 00:02:06,260 --> 00:02:09,564 This time we'll use an if total items is less than one. 29 00:02:20,354 --> 00:02:24,330 If our total items is less than 1 then we're going to add a message. 30 00:02:24,330 --> 00:02:26,350 But let's finish off our else block first. 31 00:02:27,880 --> 00:02:31,940 After a message we're going to add an else that contains the resulting items as well 32 00:02:31,940 --> 00:02:32,934 as our pagination. 33 00:02:42,664 --> 00:02:45,244 Make sure you close this else block. 34 00:02:45,244 --> 00:02:47,744 Now we're ready to go back up and add our message. 35 00:02:53,054 --> 00:02:54,574 No items were found. 36 00:03:02,674 --> 00:03:06,037 We'll also add another paragraph asking them to search again or 37 00:03:06,037 --> 00:03:07,414 browse the full catalog. 38 00:03:14,944 --> 00:03:16,804 Let's add our link to browse. 39 00:03:38,304 --> 00:03:41,191 There's one more thing we need to do to make this work properly and 40 00:03:41,191 --> 00:03:42,670 to clean things up a little more. 41 00:03:43,710 --> 00:03:47,280 If our total items are less than 1, we really don't need to do any more 42 00:03:47,280 --> 00:03:50,680 calculations before we grab the catalog results. 43 00:03:50,680 --> 00:03:54,190 We also don't want to redirect to the full catalog. 44 00:03:54,190 --> 00:03:56,504 So let's put all that within another conditional. 45 00:04:06,518 --> 00:04:13,398 If our total items are greater than 0, then we can add these calculations. 46 00:04:22,044 --> 00:04:25,140 We'll put all this within our if statement. 47 00:04:25,140 --> 00:04:29,970 So if our total items are less than 1, we'll skip over this entire block. 48 00:04:30,990 --> 00:04:34,500 We do need to add a couple default for total pages and offset. 49 00:04:36,800 --> 00:04:38,734 We'll add them right after total items. 50 00:04:49,614 --> 00:04:52,414 We can also move our pagination up here as well. 51 00:05:08,584 --> 00:05:12,064 Great, let's take a look at this in the browser again. 52 00:05:12,064 --> 00:05:17,269 Now when we do a search We see our search results, 53 00:05:17,269 --> 00:05:22,144 and when we search for something that doesn't exist we see our message that no 54 00:05:22,144 --> 00:05:25,000 items were found matching that search term. 55 00:05:26,200 --> 00:05:29,410 The last thing we need to do is integrate the search feature 56 00:05:29,410 --> 00:05:30,990 with the pagination feature. 57 00:05:30,990 --> 00:05:31,950 We'll tackle that next.