WEBVTT 00:05.500 --> 00:09.210 In this video we're going to build the strip search process. 00:09.370 --> 00:16.240 So to look for Tripps we need to improve the departure and destination and then click on the search 00:16.240 --> 00:16.860 button. 00:16.870 --> 00:20.810 So once we click on that person we want to show these trips right there. 00:21.190 --> 00:29.170 So we're going to be looking for trips going from any location within a 10 miles radius from our departure 00:29.350 --> 00:33.760 to any location within a 10 miles radius from our destination. 00:33.790 --> 00:42.120 So instead of sending the departure and the situation only We're going to need to send also the coordinates 00:42.330 --> 00:47.340 of the departure of the coordinates of the destination to the people. 00:47.400 --> 00:52.410 So this is going to be very similar to what we did in the Tripps page. 00:52.410 --> 00:58.680 So when we were creating a trip we had to give the departure and destination BOD's when we were sending 00:58.680 --> 00:59.870 the age of school. 00:59.880 --> 01:06.380 We also sent the coordinates of each of these two locations. 01:06.810 --> 01:12.540 So we're going to follow more or less the same process and we're just going to realise some of the code 01:12.540 --> 01:15.820 that we've already written to save time. 01:16.030 --> 01:16.600 OK. 01:16.890 --> 01:23.650 So we're going to go to the javascript file linked to this page which is javascript Toji is. 01:24.950 --> 01:33.170 And then we're going to write code that we are going to execute when we submits the search for. 01:34.550 --> 01:47.940 So first let's SYNNEX the form using these ID. 01:47.970 --> 01:53.800 So here is a search form id search form. 01:53.960 --> 01:55.490 So once we submit the form 01:59.310 --> 02:03.940 we want to execute this function. 02:04.230 --> 02:10.170 So it's going to have a problem in the events that we're going to use to prevent the default submission 02:10.170 --> 02:11.430 of the form. 02:11.430 --> 02:12.660 So we've done this many times. 02:12.680 --> 02:15.310 Now you must be familiar with this. 02:15.930 --> 02:22.840 Then we go going to collect all the user inputs and place them inside a variable that we're going to 02:22.840 --> 02:24.480 call data 02:27.490 --> 02:31.910 case let's see if we've already defined these variable 02:35.220 --> 02:35.930 OK. 02:36.540 --> 02:46.850 Or let's just create a variable data to post like we did the then use the serialize array function. 02:47.770 --> 02:50.960 Ok so now because the user inputs. 02:51.940 --> 02:56.860 Right now let's just print the 02:59.950 --> 03:04.660 variable they suppose in the console to make sure that everything works. 03:13.250 --> 03:18.800 So let's have a look at the console and we can see an array there. 03:18.800 --> 03:22.910 And of course our departure and destination. 03:23.250 --> 03:23.940 All right. 03:24.060 --> 03:30.430 So now we want to add to these elements the coordinates of the departure destination. 03:30.580 --> 03:33.880 So what we did in 03:36.760 --> 03:47.290 the Jones case file linked to the tips page when we were creating a trip to get the coordinates we used 03:47.350 --> 03:51.450 a function gets trip departure coordinates. 03:51.690 --> 03:56.120 OK so we're going to do the same thing. 04:05.060 --> 04:07.230 We're going to call this instead of trip. 04:07.370 --> 04:16.270 We're going to call this search get search departure coordinates that are going to define the function 04:40.690 --> 04:45.920 name meets gets search departure coordinates. 04:45.940 --> 04:51.150 OK so the IDs of the departure and destination are the same. 04:51.310 --> 04:54.480 OK so we're going to leave that as departure. 04:55.550 --> 05:02.230 And then once you go it's the coordinates of the departure we need the coordinates of the destination 05:02.710 --> 05:03.880 before going ahead. 05:03.880 --> 05:06.250 We need to define the geocoder. 05:06.250 --> 05:09.610 So it's copy this 05:15.240 --> 05:15.850 right. 05:17.890 --> 05:32.710 Now let's change the name of this function to get search the situation coordinates. 05:32.980 --> 05:33.330 OK. 05:33.350 --> 05:35.210 Now we are going to define that function 05:38.070 --> 05:40.570 it just copy the code straight from here. 05:50.980 --> 05:52.180 And change the name 05:57.750 --> 06:03.160 and we can change the submits function to submitting search requests 06:10.360 --> 06:12.790 and also we get to define that function. 06:12.880 --> 06:29.020 Same way we did right that they were going to change it. 06:29.250 --> 06:37.200 All right so the AJAX call is going to be sent to the search file 06:41.130 --> 06:41.780 OK. 06:45.570 --> 06:51.420 And you can see here the name of the data is going to be sending is data is going to be using data variable 06:51.440 --> 06:56.230 instead of data to post. 06:56.500 --> 07:00.440 So let's call this data that is defined. 07:01.570 --> 07:02.680 Right before the form 07:08.030 --> 07:08.800 OK. 07:09.460 --> 07:10.990 Because it's data every way. 07:16.160 --> 07:23.270 Then once we have caused the return they say we can then write some code that it's going to be different 07:23.270 --> 07:23.750 from this 07:27.110 --> 07:34.000 and if there is an error with the AJAX call which is going to show an error message. 07:34.290 --> 07:40.470 So if we go to the index page file we want to show the results there. 07:40.800 --> 07:43.460 And also it showed the error is that if there are any errors. 07:43.680 --> 07:49.750 So we're going to need to add a div right after the month 07:55.130 --> 07:57.790 we'll write the same code. 07:59.440 --> 08:00.080 So that wasn't 08:14.490 --> 08:19.440 give us an idea search results. 08:42.150 --> 08:49.260 So let's use the ID to show the error message. 08:49.360 --> 08:50.470 So it's save 08:53.890 --> 08:58.930 all day so for now let's just make sure that we get the right data. 08:58.950 --> 09:07.080 So instead of sending the AJAX call is going to come and this will help never just going to print in 09:07.090 --> 09:09.150 the console. 09:09.330 --> 09:12.380 The data variable. 09:13.080 --> 09:15.750 So we save and refresh 09:31.420 --> 09:41.450 so we can see there the departure designation the departure longitude latitude and longitude and latitude. 09:41.560 --> 09:44.880 So of course all the data you want to send to the PH's be found. 09:45.130 --> 09:49.540 OK so what are we going to do we're going to send all these data with the people that are going to go 09:49.540 --> 09:59.210 through all the checks and then we're going to run a query which will find the right tips for us. 10:00.000 --> 10:00.900 OK. 10:01.260 --> 10:05.870 So now it's Colvin's the age of school 10:09.310 --> 10:14.300 save is going to come back to this function later. 10:14.380 --> 10:18.560 So go inside the search file. 10:18.930 --> 10:27.410 We're going to start by sourcing a session of the connections the database. 10:27.530 --> 10:36.890 Then we're going to define all the possible error messages before checking the inputs so we can get 10:36.920 --> 10:40.800 inspired from previous proposals we created. 10:40.820 --> 10:47.680 So I'm going to open the Tripps BHP file. 10:48.340 --> 10:55.630 So basically the difference with this one is that we only have two employees here and we're going to 10:56.080 --> 11:04.210 have error messages corresponding to a missing departure missing destination invalid departure and invalid 11:04.210 --> 11:05.380 destination. 11:05.380 --> 11:11.660 So that's copy the code for the session starts and connection 11:16.650 --> 11:26.580 know regarding the error messages we wants between the parties involved departure missing an assassination 11:26.940 --> 11:28.170 and involve destination 11:32.220 --> 11:32.990 OK. 11:33.430 --> 11:36.150 Now let's check the departure of this nation 11:40.530 --> 11:42.910 where we food before doing this gets the inputs 11:45.820 --> 11:51.470 sees the same code. 11:51.600 --> 11:58.140 Now let's check the departure so you can see those we checking if the departure is empty. 11:58.280 --> 12:04.260 Then if the policy is that we check the call that is that we do the same thing for the destination 12:10.850 --> 12:17.990 OK. 12:18.210 --> 12:25.110 Right now if we have any errors we is going to echo an error message and just exit the code so we can 12:25.110 --> 12:28.220 just to the same thing we've done that 12:32.470 --> 12:38.340 by this time where we just exceed the code right here. 12:38.470 --> 12:38.820 OK. 12:38.860 --> 12:42.900 If you call error. 12:42.980 --> 12:49.700 All right so if we manage to get here that means that we've got no errors because our departure destination 12:49.940 --> 12:51.710 and of course our coordinates. 12:51.710 --> 12:59.750 So now the next step is to look for the relevant trips in the trips table. 12:59.750 --> 13:10.800 So to do that we're going to need to do some geometry because we will find trips going from near Bedford 13:11.190 --> 13:18.120 to ne love and tolerance here of a 10 miles radius. 13:18.120 --> 13:29.240 So if we look inside our table we of course the coordinates of each trip the departure and the destination. 13:29.340 --> 13:40.260 So we're going to need to find a way to write a clever query which will look for all trips going from 13:41.250 --> 13:43.480 near Bedford to near London. 13:43.890 --> 13:49.640 So in the next video we're going to do some geometry and then writes the right query.