WEBVTT 00:05.570 --> 00:10.390 In this video we're going to write code to delete a trip. 00:10.870 --> 00:17.610 So so far when we opened the edit trip model we've done a few things. 00:17.810 --> 00:22.500 So we managed to get the trip details and fill the form using those details. 00:22.790 --> 00:36.510 We also managed to write code to submit the edits form and now we going to write code to dillies. 00:37.460 --> 00:47.690 So to delete a trip we're going to send an AJAX call with the trip ID and all we need to do is run a 00:47.690 --> 00:54.270 query saying delete the trip of ID whatever the IDs 00:57.450 --> 01:04.150 we we're going to lease a trip if we click on that person so it selects the first using its ID 01:07.420 --> 01:08.790 ID of the last person 01:26.570 --> 01:27.250 he's 01:33.920 --> 01:35.840 daily trip. 01:36.880 --> 01:37.480 OK. 01:37.650 --> 01:44.560 So we're going to use the click method which will take a function for. 01:47.430 --> 01:50.170 So inside the function we're just going to send them to school. 01:50.310 --> 01:50.590 OK. 01:50.610 --> 01:56.510 With the trip ID so it copy and just call from somewhere else. 02:06.550 --> 02:12.750 OK so the Oriole here is going to be the BHB file for deleting a trip. 02:12.820 --> 02:21.790 So it's going to be that's one delete Tripps those BHB. 02:22.420 --> 02:26.470 So the data we're going to be sending here is exactly the same. 02:26.470 --> 02:31.040 So we're going to send the trip I.D. to get the I.D.. 02:31.150 --> 02:34.450 We're going to use the Invoca variable to get the data. 02:34.450 --> 02:36.870 SB is Chip I.D. OK. 02:36.880 --> 02:43.050 So if the age of school is successful we're going to have a look at the return data. 02:43.480 --> 02:53.770 So basically what this fight is going to do is going to run the query the leasing the trip if the query 02:53.770 --> 02:57.160 is successful then it's not going to return anything. 02:58.110 --> 03:05.160 OK but if the query is not successful it's going to return error. 03:05.180 --> 03:14.410 So if you've got anything returned then we know that there has been an error and we are going to show 03:14.410 --> 03:15.790 an error message straight away. 03:26.640 --> 03:35.740 And say something like the tree must be deleted. 03:35.730 --> 03:36.330 Please try again 03:42.900 --> 03:48.450 else meaning that's the query has run successfully. 03:48.460 --> 03:52.480 We're going to hide the model. 03:52.650 --> 03:58.320 OK so to hide the module. 03:58.470 --> 04:01.350 We can just select the module using its bady 04:05.140 --> 04:17.920 which is it to model and then use the modal method and give us a parameter height we've done this before. 04:18.440 --> 04:19.230 OK. 04:19.470 --> 04:27.960 So once we hit the model then we'll need to show the strips again so we're going to call the Gets Tripps 04:27.960 --> 04:28.320 function 04:40.810 --> 04:44.720 and we don't need to hide any previous errors. 04:44.990 --> 04:53.710 OK because once we hide the model opening a new model is going to hide or empty any errors that we had 04:53.800 --> 04:54.650 earlier. 04:55.180 --> 04:58.560 So set a cease fire that gives code. 04:58.560 --> 05:00.420 Now let's move to the PSP file. 05:04.640 --> 05:09.800 So first of all we're going to source a session and connect to the database 05:25.970 --> 05:31.690 Well actually we need to connect to the database but we don't actually need a session source here because 05:31.690 --> 05:33.790 we're not going to be using any session variables. 05:33.980 --> 05:38.290 OK I'm going to keep that as we have done in all other files. 05:38.360 --> 05:42.620 So let's create the query which will least the trip. 05:42.620 --> 05:56.930 So the syntax is leads from table which is CarShare trips and the condition is where we a much of the 05:56.930 --> 06:01.630 trip ID. 06:02.340 --> 06:03.410 So this creates a 06:06.550 --> 06:13.400 variable Id be going to get the ID from depos array. 06:20.080 --> 06:26.220 And that's going to be the element of key id 06:29.330 --> 06:30.630 Well actually the key is that I want to 06:38.240 --> 06:42.960 here we go right so now let's run the query. 06:43.250 --> 06:46.340 So the results inside a result variable 06:51.270 --> 06:59.520 again this will take the connection link and the query. 06:59.520 --> 07:02.930 Now let's check if the query is not successful. 07:03.390 --> 07:11.210 So in that case we're going to echo something an echo or anything here. 07:11.390 --> 07:12.570 We're going to say error. 07:12.870 --> 07:18.810 Anyway in the code we say that if this file returns anything that's means does the trip could just be 07:18.810 --> 07:19.710 deleted. 07:19.720 --> 07:22.180 OK we're just going to show those error message. 07:22.510 --> 07:23.060 OK. 07:23.220 --> 07:27.040 So now it's save and try out code 07:30.780 --> 07:31.380 OK. 07:31.650 --> 07:33.920 So let's try the first one. 07:34.350 --> 07:37.170 Delete OK says me delete it. 07:37.240 --> 07:37.620 So 07:41.590 --> 07:42.490 great. 07:43.040 --> 07:45.660 OK so everything works. 07:46.040 --> 07:48.910 And our lease code is now complete. 07:49.100 --> 07:55.820 OK so before moving on I'm just going to make a quick change to the styling on some mountain top to 07:55.820 --> 07:58.310 the my trips. 07:58.310 --> 07:58.790 Dave 08:07.100 --> 08:08.590 Quint idea of my trips 08:17.450 --> 08:19.300 it's a top 08:22.240 --> 08:30.050 of 26 Hills instance and also it's on the bottom. 08:30.520 --> 08:39.270 Let's go 100 so that if we have too many trips then it doesn't overlap with the foot to save refresh 08:41.830 --> 08:43.480 rates. 08:43.480 --> 08:43.720 All right. 08:43.720 --> 08:49.000 So in the next video we are going to move to the search algorithm.