WEBVTT 00:00:07.310 --> 00:00:07.650 All right. 00:00:07.650 --> 00:00:13.790 Now as we run the query deleting all the empty notes we need to check if the query is successful. 00:00:14.100 --> 00:00:14.880 OK. 00:00:14.880 --> 00:00:23.640 So for a delete query the function my school-I query is going to return true or false. 00:00:23.800 --> 00:00:27.410 Ok so if successful is going to return true. 00:00:27.420 --> 00:00:29.420 Otherwise it's going to be false. 00:00:29.430 --> 00:00:34.180 So so we're going to check if a result is false. 00:00:34.840 --> 00:00:35.660 OK. 00:00:36.360 --> 00:00:42.890 So if the opposite of results. 00:00:43.110 --> 00:00:44.890 OK. 00:00:45.810 --> 00:00:48.400 So it is going to be true if results is false. 00:00:48.600 --> 00:00:54.870 So if that's the case we're going to echo its message. 00:00:54.870 --> 00:00:57.040 So it's going to be a day 00:01:02.780 --> 00:01:07.470 and which is going to give it a couple of pluses so 00:01:10.710 --> 00:01:14.680 alert and alert warning. 00:01:15.140 --> 00:01:16.830 OK. 00:01:17.820 --> 00:01:23.570 Let's write something inside a div like an error occurred. 00:01:23.610 --> 00:01:24.450 All right. 00:01:24.960 --> 00:01:25.500 So 00:01:28.110 --> 00:01:31.090 right after that we're going to exit the code. 00:01:31.360 --> 00:01:32.010 OK. 00:01:32.340 --> 00:01:37.740 So let's save and try this so let's try something 00:01:41.220 --> 00:01:43.640 wrong so that we can get an error. 00:01:44.010 --> 00:01:44.870 OK. 00:01:45.300 --> 00:01:50.410 So let's refresh. 00:01:52.200 --> 00:01:55.800 OK so we can see our alert message. 00:01:56.030 --> 00:01:56.400 All right. 00:01:56.400 --> 00:02:01.920 Now let's Royse the correct query and test again. 00:02:03.050 --> 00:02:03.520 OK. 00:02:03.560 --> 00:02:07.310 And we can see that we echoed these couple of days. 00:02:07.480 --> 00:02:09.780 Okay there's your cause of the end of our code. 00:02:09.810 --> 00:02:10.890 All right. 00:02:10.890 --> 00:02:17.450 So now we're going to run another query to look for notes. 00:02:17.660 --> 00:02:19.520 OK. 00:02:19.710 --> 00:02:21.400 Created by our user. 00:02:21.750 --> 00:02:30.200 OK so the query is going to be as following so you going to store the query in the Israel variable. 00:02:30.480 --> 00:02:36.980 So this time we going to select records. 00:02:37.190 --> 00:02:37.910 OK. 00:02:38.040 --> 00:02:41.560 From our notes table. 00:02:42.900 --> 00:02:48.000 OK. 00:02:50.030 --> 00:02:53.880 And the condition is going to be where 00:02:57.840 --> 00:03:00.060 the user id pay 00:03:06.120 --> 00:03:07.260 corresponds to 00:03:10.260 --> 00:03:15.550 the user id as we stored inside our variable user ID. 00:03:16.590 --> 00:03:17.030 OK. 00:03:17.100 --> 00:03:25.500 So we're using single quotes using double quotes in there so we can use the variable straight away inside 00:03:25.960 --> 00:03:26.800 our string. 00:03:27.100 --> 00:03:27.450 OK. 00:03:27.460 --> 00:03:36.090 So now when we show all the notes we're going to order them in a way that's the most recent ones. 00:03:36.360 --> 00:03:36.990 OK. 00:03:36.990 --> 00:03:38.640 We'll show at the top. 00:03:38.880 --> 00:03:40.320 So we're going to order 00:03:43.860 --> 00:03:48.820 by time descending. 00:03:49.110 --> 00:03:54.320 OK. 00:03:57.410 --> 00:03:57.980 OK. 00:03:57.990 --> 00:04:05.940 Because the value of time for the most recent ones is going to be the biggest. 00:04:05.940 --> 00:04:07.820 All right. 00:04:08.520 --> 00:04:15.210 Now let's run our query and check if you cause any errors. 00:04:15.210 --> 00:04:20.490 So you can either write us statements where you saw the results inside our results. 00:04:20.490 --> 00:04:21.290 Object. 00:04:21.390 --> 00:04:22.230 OK. 00:04:22.230 --> 00:04:25.230 And then check if you've got any errors. 00:04:25.230 --> 00:04:29.030 Otherwise you can straight away do like this. 00:04:29.220 --> 00:04:35.700 So you can do. 00:04:37.740 --> 00:04:44.800 And if statements where your rights in the condition something like this. 00:04:44.850 --> 00:04:52.800 So basically he's going to check if this bet OK is true or not. 00:04:53.100 --> 00:04:54.380 OK. 00:04:55.440 --> 00:05:04.140 Basically one you use a Select query the result object the results variable is going to store either 00:05:04.140 --> 00:05:07.330 an object if everything goes fine. 00:05:07.590 --> 00:05:11.790 Otherwise it's going to return false. 00:05:11.820 --> 00:05:12.780 OK. 00:05:13.260 --> 00:05:17.140 If it's an object this is going to be considered as true. 00:05:17.170 --> 00:05:27.630 OK so if that's an object we can write some code else we would get if we get false then we're going 00:05:27.630 --> 00:05:32.940 to echo in alerts message again so it starts with the alerts message. 00:05:32.940 --> 00:05:40.920 So we're going to echo something like that actually the code like this 00:05:44.400 --> 00:05:46.160 if you want to do some debugging. 00:05:46.290 --> 00:05:48.850 You can also use the school-I. 00:05:49.020 --> 00:05:51.490 And this core error function OK. 00:05:52.050 --> 00:06:01.480 Which will take as a barometer or a link variable and will return the last error. 00:06:01.720 --> 00:06:04.000 OK. 00:06:05.250 --> 00:06:11.690 While the error corresponding to the loss query that we've lost we've run OK. 00:06:11.970 --> 00:06:13.300 And you can write something like 00:06:16.650 --> 00:06:18.700 error. 00:06:21.190 --> 00:06:22.750 Unable to execute 00:06:25.830 --> 00:06:27.400 the query. 00:06:28.960 --> 00:06:31.990 OK. 00:06:32.220 --> 00:06:37.050 And then you add the error using a dot like this. 00:06:37.370 --> 00:06:46.760 OK so I'm going to comment that's when hopefully we don't get any errors so I save. 00:06:46.770 --> 00:06:52.440 Now let's go back to the first case where the result variable corresponds to an object's. 00:06:52.650 --> 00:07:00.570 So first of all before we try to get the different notes of our user We're going to check how many rows 00:07:00.660 --> 00:07:02.440 We've got inside our objects. 00:07:02.540 --> 00:07:03.240 OK. 00:07:03.630 --> 00:07:05.440 So we're going to have an if statement 00:07:08.730 --> 00:07:14.410 checking aved the number of rows is greater than zero. 00:07:14.640 --> 00:07:20.220 If that's the case then we're going to extract all the user knows otherwise 00:07:24.490 --> 00:07:29.420 we're going to echo an alert message. 00:07:29.580 --> 00:07:30.090 OK. 00:07:30.180 --> 00:07:33.700 Saying something like you have not created any notes yet. 00:07:33.700 --> 00:07:33.990 OK. 00:07:34.020 --> 00:07:40.340 So that's going to be more or less similar to this. 00:07:40.870 --> 00:07:44.410 And instead of that we're going to rise. 00:07:45.300 --> 00:07:50.570 You have not created an instance. 00:07:51.660 --> 00:07:53.060 OK. 00:07:53.310 --> 00:07:57.470 Now the condition is going to be number of rows greater than zero. 00:07:57.540 --> 00:08:06.720 So the function is going to be my escrow my number of rows like this is going to take our results variable 00:08:06.960 --> 00:08:09.280 as a barometer. 00:08:09.960 --> 00:08:13.840 When we check in here that's strictly greater than zero. 00:08:14.160 --> 00:08:20.110 So if that was the case we're going to start fetching the difference records. 00:08:20.580 --> 00:08:24.990 So if you remember we're going to use a while statements. 00:08:25.950 --> 00:08:26.850 OK. 00:08:26.940 --> 00:08:34.930 So the condition inside the while statements is going to be the outputs of the function. 00:08:34.920 --> 00:08:39.460 My goal I underscore fetch and this core array. 00:08:40.290 --> 00:08:47.670 So quick reminder this function is going to take one or two promises so the first parameter is going 00:08:47.670 --> 00:08:49.970 to be our result object. 00:08:50.250 --> 00:08:55.950 And the second one depends on how we want the outputs. 00:08:55.990 --> 00:09:02.330 So it's going to be either and as we say all numeric array Abo's. 00:09:02.500 --> 00:09:04.390 So let's go for an agitated one. 00:09:04.710 --> 00:09:05.450 Okay. 00:09:06.000 --> 00:09:10.080 I was going to be using keys later on to get all the 00:09:12.750 --> 00:09:14.180 values inside the array. 00:09:14.380 --> 00:09:14.840 OK. 00:09:15.180 --> 00:09:20.470 So this function will fetch the different recall's who's going to start with the first row inside our 00:09:20.460 --> 00:09:25.600 results variable then the second one the third one and every time you call this function he's going 00:09:25.600 --> 00:09:27.740 to return the next row. 00:09:28.120 --> 00:09:31.670 Once we don't have any rows left then he's going to return. 00:09:31.680 --> 00:09:32.420 No. 00:09:32.790 --> 00:09:38.500 So what we're going to do we can test all the hours of this function inside 00:09:41.570 --> 00:09:43.690 a variable they're going to call. 00:09:44.110 --> 00:09:44.960 OK. 00:09:45.620 --> 00:09:51.800 So basically the while condition is going to be disparate. 00:09:52.030 --> 00:09:52.710 Right. 00:09:52.900 --> 00:09:58.920 But at the same time we are going to be storing the results of this inside the robot. 00:09:59.370 --> 00:10:00.040 OK. 00:10:00.400 --> 00:10:04.530 So every single record is going to be stored inside. 00:10:04.610 --> 00:10:06.200 That's terrible. 00:10:06.200 --> 00:10:06.950 All right. 00:10:07.340 --> 00:10:13.430 So the rule very well is going to be and as it's very So with the keys of our array are going to be 00:10:13.430 --> 00:10:16.560 the ID user id notes and then type. 00:10:16.730 --> 00:10:17.630 OK. 00:10:18.290 --> 00:10:24.450 So for each record we're going to echo a notes just like that. 00:10:24.520 --> 00:10:25.270 OK. 00:10:25.660 --> 00:10:37.210 So let's copy code from the dummy notes that we created earlier like this. 00:10:37.470 --> 00:10:43.120 Crystalise this copy that's in there. 00:10:45.500 --> 00:10:54.060 So the contents of each notes is going to correspond to the elements of key notes. 00:10:54.230 --> 00:10:54.730 OK. 00:10:54.860 --> 00:11:01.590 So we're going to create a variable that we're going to call notes. 00:11:01.730 --> 00:11:02.400 OK. 00:11:02.770 --> 00:11:05.890 And that's where we are going to store the contents of it. 00:11:06.180 --> 00:11:06.450 OK. 00:11:06.470 --> 00:11:06.800 So 00:11:11.090 --> 00:11:14.410 to do that we're going to access the IRO array. 00:11:14.500 --> 00:11:15.010 OK. 00:11:15.200 --> 00:11:22.730 And then we're going to use the key note. 00:11:22.750 --> 00:11:23.840 OK. 00:11:24.620 --> 00:11:24.910 All right. 00:11:24.910 --> 00:11:27.290 Now let's do the same thing with time. 00:11:27.320 --> 00:11:37.580 So instead of showing this dates and time of day we're going to use a variable that we're going to call 00:11:37.660 --> 00:11:39.410 time. 00:11:39.620 --> 00:11:42.500 So this variable 00:11:45.350 --> 00:11:59.090 is going to correspond to the value of the elements of key time. 00:11:59.300 --> 00:12:01.870 All right. 00:12:02.240 --> 00:12:08.750 Later on we will need the notes ID especially when we want to delete a certain note. 00:12:08.750 --> 00:12:16.760 So if you remember we need to get the ID of the notes through Ajax before we delete the notes so that 00:12:16.820 --> 00:12:20.900 ID will need to be hidden somewhere inside the nodes. 00:12:21.200 --> 00:12:29.580 So we're going to do going to places as an ID of the day itself. 00:12:30.420 --> 00:12:31.000 OK. 00:12:31.490 --> 00:12:35.400 So we're going to use a variable I'm going to call notes ID. 00:12:36.250 --> 00:12:36.830 OK. 00:12:36.860 --> 00:12:41.420 So to get the nodes ID we're going to go to our row 00:12:44.920 --> 00:12:48.020 and use the key 00:12:50.990 --> 00:12:51.750 ID. 00:12:52.120 --> 00:12:54.840 OK. 00:12:56.670 --> 00:13:00.870 All right let's place this at the top. 00:13:01.730 --> 00:13:03.520 That's better. 00:13:03.650 --> 00:13:12.700 All right now regarding time we want to show show the time and all dates and time in this format. 00:13:12.760 --> 00:13:13.280 OK. 00:13:13.370 --> 00:13:20.920 So once you extract that time from the notes table you're going to get a number like this. 00:13:20.920 --> 00:13:27.040 So you will need to convert that number which is the Unix time sign you'll need to convert it to something 00:13:27.130 --> 00:13:28.240 like this. 00:13:28.250 --> 00:13:30.280 So to do that if you're a member 00:13:33.350 --> 00:13:36.230 you need to use the Date function. 00:13:36.290 --> 00:13:39.500 So today's function is going to take a couple of promises. 00:13:39.560 --> 00:13:43.490 So the first barometer is going to be four months. 00:13:43.630 --> 00:13:44.590 You'd like to use. 00:13:44.640 --> 00:13:49.340 And the second barometer is going to be the time variable. 00:13:50.410 --> 00:13:51.040 OK. 00:13:51.050 --> 00:13:54.620 So we want to use these formats. 00:13:55.580 --> 00:13:59.720 So we want the full month followed by the day. 00:13:59.870 --> 00:14:00.970 And then the year. 00:14:01.170 --> 00:14:01.690 Okay. 00:14:01.700 --> 00:14:06.180 And then our minutes second and then AM or PM. 00:14:06.230 --> 00:14:12.470 All right so that format corresponds to the following so copies of copies are there for a full month 00:14:12.910 --> 00:14:22.130 and then the small d and then capital Y for the full year. 00:14:22.460 --> 00:14:23.290 Okay. 00:14:23.300 --> 00:14:27.260 And then space and then the our 00:14:31.040 --> 00:14:36.530 minutes seconds and then capital a 4 a.m.. 00:14:36.700 --> 00:14:37.370 Okay. 00:14:37.630 --> 00:14:45.200 So you don't have to remember all these all they need to do is go back to the time section in the BHB 00:14:45.460 --> 00:14:48.600 chapter and you'll find a reference to these. 00:14:48.830 --> 00:14:49.880 OK. 00:14:50.550 --> 00:14:51.560 Well right now it's 00:14:54.450 --> 00:14:58.810 save and refresh our page. 00:14:59.650 --> 00:15:03.180 So it looks like the query is returning an empty results. 00:15:03.200 --> 00:15:05.980 That's why we don't see any notes here. 00:15:05.990 --> 00:15:11.240 So let's check out code to make sure you've got the right user id 00:15:14.500 --> 00:15:16.020 so we're missing. 00:15:16.040 --> 00:15:18.500 And the score in the session array. 00:15:18.720 --> 00:15:19.210 Okay. 00:15:19.250 --> 00:15:28.220 So now if we refresh the page we can see that we are getting the notes corresponding to our user. 00:15:28.610 --> 00:15:33.280 Okay. 00:15:37.090 --> 00:15:37.430 All right. 00:15:37.420 --> 00:15:41.740 In the next video we're going to write code corresponding to creating a node