WEBVTT 00:00:07.840 --> 00:00:15.600 In this video we're going to learn how to abbé's data in a table using a Ph.D. and my a school bus before 00:00:15.600 --> 00:00:17.200 we go ahead and do that. 00:00:17.250 --> 00:00:26.340 Let's just go back to our previous file and just try a few more school queries OK to get different results 00:00:26.340 --> 00:00:26.750 . 00:00:26.820 --> 00:00:35.250 So the query we have tried was select some from users which gave us all the rows in the original table 00:00:35.260 --> 00:00:35.370 . 00:00:35.490 --> 00:00:36.210 OK. 00:00:36.750 --> 00:00:40.980 And now we can try another query. 00:00:41.100 --> 00:00:41.600 OK. 00:00:41.820 --> 00:00:49.620 So for example we can select all the records in our table where 00:00:53.080 --> 00:00:58.710 OK a certain field equals something specific. 00:00:58.710 --> 00:01:04.110 So for example we want all the records where the first name 00:01:07.020 --> 00:01:15.610 is George for example with first name equals. 00:01:16.010 --> 00:01:20.250 And now we're going to place the value inside single quotes. 00:01:21.250 --> 00:01:23.900 OK. 00:01:26.600 --> 00:01:32.620 You save and refresh you can see they gave us only one row. 00:01:32.970 --> 00:01:38.220 OK we can try another one. 00:01:38.220 --> 00:01:39.090 So for example 00:01:43.050 --> 00:01:46.190 you can still selects all the uses. 00:01:46.890 --> 00:01:48.180 OK. 00:01:48.740 --> 00:01:50.850 At this time we're going to use another keyword. 00:01:50.870 --> 00:01:51.190 It's. 00:01:51.220 --> 00:02:00.120 ORDER BY and we want to order the rows by last name for example. 00:02:01.340 --> 00:02:05.640 So if I see one refresh we can see that's the rows. 00:02:05.640 --> 00:02:09.870 Now they are ordered in alphabetical order by last name. 00:02:10.260 --> 00:02:18.540 OK so if you want the opposite order then we use the same query but we are just going to 00:02:22.110 --> 00:02:22.860 change 00:02:25.720 --> 00:02:36.270 odds a keyword descending like that's OK. 00:02:36.310 --> 00:02:44.910 Now if we save and refresh we can see now that the order is in the descending order OK. 00:02:45.240 --> 00:02:52.240 All right so now let's see how to update records in our table. 00:02:53.350 --> 00:02:59.050 So again we connect it to our database using the same code as before. 00:02:59.240 --> 00:03:04.020 And now we are going to Bates records in our table. 00:03:04.470 --> 00:03:10.230 So we going to create a query that we're going to store in a variable as well. 00:03:10.820 --> 00:03:11.440 OK. 00:03:11.790 --> 00:03:20.040 And now inside our query we're going to use and you ask you all keyword eight's updates. 00:03:20.330 --> 00:03:25.800 So we're going to say updates the name of the table users. 00:03:26.320 --> 00:03:27.410 OK. 00:03:28.350 --> 00:03:30.650 And we're going to use another key word here. 00:03:31.050 --> 00:03:32.570 Set. 00:03:33.450 --> 00:03:36.930 And then we're going to say which field we want to change. 00:03:36.930 --> 00:03:39.810 So for example let's say that we want to 00:03:45.090 --> 00:03:47.260 change the last name. 00:03:47.760 --> 00:03:48.410 OK. 00:03:48.720 --> 00:03:57.780 Of all people with the first name George we're going to change these people's last name to Wilson for 00:03:57.780 --> 00:03:58.660 example. 00:03:59.130 --> 00:03:59.900 OK. 00:04:00.330 --> 00:04:11.370 So let's try that so we're going to say set last name equal and they're going to use single quotes for 00:04:11.370 --> 00:04:12.380 the new value. 00:04:12.450 --> 00:04:13.970 Wilson. 00:04:14.980 --> 00:04:17.210 All right. 00:04:17.230 --> 00:04:29.690 And the condition is where a first name equals George. 00:04:30.540 --> 00:04:36.440 OK so let's save this refresh our page. 00:04:36.490 --> 00:04:43.580 That is executed or before we do that let's just finished the code. 00:04:44.330 --> 00:04:45.670 OK. 00:04:45.990 --> 00:04:50.040 And say whether this has been successfully executed or not. 00:04:50.070 --> 00:04:57.130 So we're just going to use the same code as before. 00:04:57.420 --> 00:05:00.210 So you know when you check the condition 00:05:03.810 --> 00:05:04.420 OK. 00:05:04.470 --> 00:05:08.100 First of all we need to execute the Esker the query. 00:05:08.100 --> 00:05:09.070 We haven't done that yet. 00:05:09.150 --> 00:05:09.580 OK. 00:05:09.690 --> 00:05:10.350 So let's do that. 00:05:10.340 --> 00:05:23.260 So my skill I underscore queery going to take the link variable and the query. 00:05:24.930 --> 00:05:36.150 So this will execute the query and if that's true then are you going to echo a paragraph saying that 00:05:39.240 --> 00:05:43.530 data was updated successfully. 00:05:44.590 --> 00:05:46.400 OK. 00:05:48.330 --> 00:05:55.380 Else we are going to echo another paragraph 00:05:58.590 --> 00:06:03.780 saying error unable to execute 00:06:07.320 --> 00:06:08.410 the query. 00:06:08.850 --> 00:06:09.780 OK. 00:06:10.260 --> 00:06:14.310 And we can get the results string right after this 00:06:14.310 --> 00:06:22.830 . 00:06:22.830 --> 00:06:29.370 And that we're going to use the function my skill I and this call error which is going to take as a 00:06:29.370 --> 00:06:35.350 parameter or link variable our connection available. 00:06:35.670 --> 00:06:36.110 OK. 00:06:36.330 --> 00:06:40.180 So if we save and refresh. 00:06:41.220 --> 00:06:43.710 OK it says data was updated successfully. 00:06:43.710 --> 00:06:49.590 So let's have a look at this as I'm going to refresh now and we're going to look at the new last name 00:06:49.620 --> 00:06:55.960 of George and you can see that then your last name of George is Wilson. 00:06:56.260 --> 00:06:56.960 OK. 00:06:56.970 --> 00:06:59.490 So the order changed because we are 00:07:02.190 --> 00:07:04.850 showing the data by last name. 00:07:04.880 --> 00:07:05.980 OK descending. 00:07:06.020 --> 00:07:06.820 That's right. 00:07:07.240 --> 00:07:08.350 OK. 00:07:08.460 --> 00:07:16.400 Otherwise we can use common descent now and show the first one want to save and fresh. 00:07:16.460 --> 00:07:18.800 OK. 00:07:19.270 --> 00:07:25.510 All right so that's how we can update data in a table. 00:07:25.890 --> 00:07:39.090 If we don't add any condition like this then all all uses all the records are going to have their last 00:07:39.090 --> 00:07:40.880 name changed to Wilson. 00:07:41.250 --> 00:07:42.210 OK. 00:07:42.210 --> 00:07:47.540 And also if you want to add an extra condition so for example. 00:07:47.880 --> 00:07:55.610 So we want to change the last name to Wilson for all uses with I am 00:08:00.780 --> 00:08:10.890 with a last name or a first name piece for example. 00:08:10.890 --> 00:08:19.690 And so we're going to use the keyword and for this and email address for example. 00:08:19.770 --> 00:08:28.470 Email equals Sovaldi inside single quotes and we want to use that for example. 00:08:28.470 --> 00:08:36.690 So now all you use is having this last name Tyla And this email address I going to have. 00:08:36.990 --> 00:08:43.310 Or are you having the first name pizza and email like this are going to have the new. 00:08:43.350 --> 00:08:46.190 Last name Wilson. 00:08:46.300 --> 00:08:51.150 OK so if we save and refresh the page. 00:08:51.240 --> 00:08:53.280 So data was updated successfully. 00:08:53.280 --> 00:08:59.450 So if you're fresh Now we can see that both these have caught now new. 00:08:59.450 --> 00:09:01.400 Last name Wilson. 00:09:01.500 --> 00:09:02.470 All right. 00:09:02.940 --> 00:09:11.420 OK so in the next video we will see how to delete data using PSP and my school