While I was experimenting with MYSQL queries, I wondered if I could get week of the month from a give date by using the MYSQL query rather than using backend languages like PHP & JAVA. So I created a query for it.
Here is the simple employees table with more than 200 thousand rows.
And it does have a column called “hire_date” with a data type as date.
What I am going to do is just copy-paste the query that I’ve created.
Of course, you can copy-paste the code from the link given in the description.
Please note that in my case, Monday as a first day and Sunday as a last day of the week.
From FLOOR to WEEK_OF_MONTH is the main formula which will give you exact week count.
Let’s check the output.
The 20th of September 2022 belongs in 4th week.
The 11th of September 2022 represents 2nd week because it is the Sunday and also the last day of 2nd week.
You can replace the table and column name with your preferred table and columns to verify it.
Step 3 : Open pubspec.yaml file, inside the "dependencies" add 2 lines.
http: any
dio: any
-----------------------------
Step 4 : Click on "pub get" link which will appear on ANDROID STUDIO.
-----------------------------
Step 5 : Install XAMPP's latest version.
-----------------------------
Step 6 : Run XAMPP and start APACHE & MySQL.
-----------------------------
Step 7 : On any browser, on URL bar, hit http://127.0.0.1/phpmyadmin/ & create a new database “test”. Go to it’s SQL, in textarea, copy-paste the following query.
Step 10 : Open the command prompt and enter "ipconfig" (to find out the IPv4 address for localhost). Make sure that it is same as an IP address which is added on the left side of "/flutter_test/store_data_flutter.php". If not, then add the IP address from command prompt. And then run the project.
==================
Flutter | POST the JSON Data Through API Using Dio | PHP as a Backend
In this tutorial, we shall create a project which can send data through API using GET & POST Methods.
We shall be using a PHP as a back-end language for the API and shall store the JSON in database.
We shall be referring a blog which contains steps to approach the task. Link of that blog is giving in the description.
First step is to create an empty Flutter project.
From 2nd step, copy-paste the whole code and paste it in main.dart file.
For 3rd step, open pubspec.yaml file and add those 2 lines under dependencies.
Make sure it is at the same level as flutter, then click on PUB GET to download important libraries.
We completed 4th point, and for the 5th point, we have to install XAMPP which will create a local domain in your computer. This will help us to create an API.
Link for XAMPP installation tutorial is given at the right-top-corner.
I already installed it so I am going to run it.
In 7th step, I shall create a database table by copy-pasting the SQL query in PHPMYADMIN.
First create a database called “test”. Click on it, and click on SQL tab.
Paste the QUERY there and execute it.
In next step, we have to create a folder called “flutter_test” in htdocs folder and then create an empty PHP file in it. Give it a name as “store_data_flutter.php”
Open that file in any text-editor, and copy-paste the code from step 9.
At last, open a command prompt and type command IPCONFIG.
Search for IPv4.
Choose any one from IPv4 and make sure that it is same an IP in flutter code. If not, then replace IP address to the one shown in your command prompt.
In response, an API returns a JSON which is displayed in console.
And when we go back to phpmyadmin, and check the table data, you will see our entered data there.
To switch from POST to GET, change function name to get. Also, in PHP code, change $_POST to $_GET.