 Alright, welcome back. In the last video we managed to insert our default data into our database, but this time around I'm going to start evaluating, we're going to use an option in our database, so that will be stored in our WP options, and this will be temporarily holding our data, and once our data changes with our API and we query it, it will go into the options. If the options is different from what we have in the database, then we will store that data inside our database, so that we don't have extra inputs inside our custom database, but we only have data that is actually important, showcasing the changes that we are having. So what we're going to do is we're going to come back to our plugin, and we're going to look at our function here. In our function here is where we are collecting our balance, and we are adding it. So what we're going to do is always query for our data, and then we save it as an option. So what we're going to do here is we're going to check and say if we have an option to press account balance, that is the option we're going to have, we're going to look for it. If it is getOption, get underscore option, and this is the value that we need, so we're going to get if this option exists, then we should query and check if it's the same with the balance that we have from this particular point. So we're going to say if the bank, the balance, if the balance is equal to the option that we do have here, then we should return, we shouldn't, nothing should happen. However, if they are different, we're going to either update the option, the option we need to have is our tpress, let me increase this here. First of all, let me change the value here, we need to add the value and update this here, and then we're going to get our option that we want is this copy, pastits here. So we're going to look for the option of tpress bank balance, account balance, and then we're going to update it with the new balance here. So let me save this and let's try to run this particular plugin. So I'll click on this, we seem to have an error because I did not add a semicolon here. So let's go back and when I reload, we have our bank balance as this, and let me check inside our options to see what we have here. We have our option and it actually is stored at 1030 and we are good to go. So the next thing that we're going to do here is to check if our balance that we've actually stored, if our option of this is equal to the last row that we have in terms of our database, we need to check the last piece of information that we have in our database. So I'm going to create a new function that will be running every other time when we query for our balance. So I'm going to separate this into a different function. Function will be update the database balance. So I'm going to save this here and I'm going to copy this, save this and come back to our database manager and I'll create a new function like this and then we shall save this. So in here, we're going to first get the details that we have. We're going to check for the last row of data that we have in our database and then we're going to insert if there is any difference. So we're going to essentially need all this information here. So we shall get wpdb and we'll have our table name. Now before we insert all of this, I'll comment this out. We are going to check for two things. We're going to first get last entry in the database and then we're going to check if that entry is actually equal to the option over the t-press, the option that we actually have in here which is this. So we're going to just get this here and we're going to say if it is equal to that then we return if there are any different then we shall insert a new field of information in here. So first of all let's go do that SQL query to get the last entry in the database. So we're getting the last record in our database by selecting all from the table name then we're ordering by and organizing them in descending order then we limit it to only one. So we have our results here. So since we have this as an object we are going to be looking for the results and we are looking for the balance here and the balance is the lower b. So we'll save this as this. Let's try to run it and it's giving us null. So the balance is null. What I need to do is change this into an intval. Let's see what it gives us. It gives an integer of zero. So we can still use it as null or any other way. We really don't mind what it is. So the result is all we need at the end of the day. So once we get this result we're now going to juxtapose it against what we have here. So I'll duplicate this then uncomment and then I'll start by saying if this result balance if our result balance is equal to we're not going to type in it for the string if it is equal to what we have here then what we're going to do is return again. So we return meaning don't run any other code after this. However if they are different let me take away this ladder here. If they are different then we are going to run this code here. We're going to insert into the table name. We'll add the current time by my siko and then the balance that we get here we get from getOption here is what we are going to apply at this point. So I'll save this and then let's run it and go. So I'll run it. Our balance is still that which is good. Let's go and reload our database here and we're going to see that now in our database we've actually updated it and added a new row of information. So let me try to run this again. I'll run it thrice. So we've queried for our data. If everything works out as it should be the balance is the same as the option. So we've not updated meaning we have to cross check and we'll see that as we reload here our database is getting this over and over because this is way above so I'll move it down to after updating the option save this. Let me drop all we have five entries here. I'll run this three times and then reload this page and we'll see that we still have our five rows here so it is actually working out well. So whenever the balance is the same as this we get a new difference. So let me go manually adjust the balance that I have on the other side. So if we check again now our balance is less than 200 as it's less this time around so if I click this we'll see that our balance is actually new. That's our SMS that's coming from our phone. Now let me reload this here. We'll see that our database actually updates with the right information that we are having. So this is working out well. I think it works exactly as we need it to. In the next video we'll be checking out how to actually send our SMS's but we'll shall contrast them against our balance to find out whether our balance is actually doing well for us to be able to send the SMS or if our balance is less than sending the SMS then we don't send the SMS we have to edit the number of entries we have to make in our SMS for our user to have some proper interaction. So thank you for watching the video if you enjoyed this please give it a thumbs up and like the video, share it with your friends. Let me know in the comments how this is going for you. Thank you for watching and nice coding.