INFO3410 Lab Exam
The [url removed, login to view] file provided will be used to complete the following questions.
Write PHP Code to complete the following tasks in a PHP file ‘[url removed, login to view]’:
1. Create an associate array called “crop” that will store the name of the crop “banana”, the price “2.0” and the unit “kg”
2. Create an indexed array called “crops” add the crop array created in 1 to this new array crops.
3. Add the following information to the end of the crops array:
a. Orange 5 per lb.
b. Cabbage 10 per bundle
c. Peas 10 per kg.
4. Using PHPMyAdmin create the database called “ttagri” which contains a table “commodities”. The commodities table have the following columns:
a. id – number – primary key – auto increment
b. name – varchar 100 – not null
c. price - double – default 0 – not null
d. unit – varchar 10 - default lb – not null
5. Write a function called “saveCrops” that will retrieve a collection of crops and store each crop in the database. Note that each crop in the collection is stored as an associative array as created in Q1.
6. Test the function with the array and values created in Q2 and Q3. After operation is performed comment the call to the saveCrops function to keep it from repeating multiple times.
7. Write a function called “getAllCrops” that will retrieve the records from the database, store each record as an associative array where the columns are the keys and finally return a collection (indexed array) of all of the crops retrieved from the database.
8. Using the function created in Q7 display JSON data for the records stored in the database fro crops.
I NEED DONE IN 30MINS