Tuesday, 3 May 2016

WEEK10_Class of MySQL and Database Integration

Database is integrated collection of data

DBMS is provides machanism for storing and organizing data and also allow user to access and store data without addressing internal representation of database.

Relational database
-- consists of data corresponding to one another 
-- most popular database system in use
-- use SQL to create queries


SQL Data Manipulation Language (DML)
- SELECT
- UPDATE
- DELETE
- INSERT INTO

SQL Data Definition Language (DML)
- CREATE TABLE
- ALTER TABLE
- DROP TABLE
- CREATE INDEX
- DROP INDEX

Introduction to Database Interface (DBI)
  • database part of distributed application
  • driver - helps program access databases
  • interface
  • database interface
This link can help you more undestanding about (selected data, insert data, delete selected data, update selected data)

Advantages of using database to store web data:
  1. faster access
  2. better concurrent access
  3. easier changes to data and script
  4. increased security
There are four step to access MySQL via PHP:
  1. STEP 1: Make a connection to the MySQL database server
  2. STEP 2: Select the database within MySQL that you want to work with
  3. STEP 3: Issue an SQL statement / create the query
  4. STEP 4: Iterate through the SQL Result Set

WEEK8_Lab Session

Today, we are doing some exercise on past year question.

this is past year question:
http://www.psb1.uum.edu.my/ks/Kolej%20Sastera%20dan%20Sains/UUMCASsem1_1516/PUSAT%20TEKNOLOGI%20MEDIA%20%26%20KOMUNIKASI/STIV3013_1_2015_2016.pdf

We discussed about Section B (75%), our lecturer said if you done and know how to do this part, u can pass in the exam..Well, i trust because it is difficult....

ANSWER:

//retrieved information from the form
    
    $name = $_POST["name"];
    $matric = $_POST["matric"];
    $stiv1023_mark = $_POST["stiv1023_mark"];
    $stiv2023_mark = $_POST["stiv2023_mark"];
    $stiv3013_mark = $_POST["stiv3013_mark"];
    $vkhb2031_mark = $_POST["vkhb2031_mark"];

//calculate grade for each course by calling calculateGred() function
   
    $stiv1023_gred = calculateGred($stiv1023_mark);
    $stiv2023_gred = calculateGred($stiv2023_mark);
    $stiv3013_gred = calculateGred($stiv3013_mark);
    $vkhb2031_gred = calculateGred($vkhb2031_mark);

//calculate point for each course by calling calculatePoint() function
   
    $stiv1023_point = calculatePoint($stiv1023_gred);
    $stiv2023_point = calculatePoint($stiv2023_gred);
    $stiv3013_point = calculatePoint($stiv3013_gred);
    $vkhb2031_point = calculatePoint($vkhb2031_gred);

//calculate TotalPoint based on point for each course and credit
    
    $TotalPoint = $stiv1023_point * 3 + $stiv2023_point * 3 + $stiv3013_point * 3 +    $vkhb2031_point * 1;

//calculate GPA based on TotalPoint and total credit
   
    $GPA = $TotalPoint / 10;

//calculate final result by calling calculateResult() function
   
    $result = calculateResult($GPA);
   
//function to calculate the grade based on mark
   
    function calculateGred($mark)
    {
        if ($mark >= 90)
            $gred = "A";
           
        else if ($mark >= 80)
            $gred = "B";
           
        else if ($mark >= 70)
            $gred = "C";
           
        else if ($mark >= 60)
            $gred = "D";
           
        else if ($mark >= 50)
            $gred = "E";
           
        else
            $gred = "F";
       
        return $gred;
    }

//function to calculate the point based on grade
   
    function calculatePoint($gred)
    {
        if ($gred == "A")
            $point = 4.00;
           
        else if ($gred == "B")
            $point = 3.50;
           
        else if ($gred == "C")
            $point = 3.00;
           
        else if ($gred == "D")
            $point = 2.50;
           
        else if ($gred == "E")
            $point = 2.00;
           
        else
            $point = 1.00;
           
        return $point;
    }
   
//function to calculate the result based on GPA
   
    function calculateResult($GPA)
    {
        if ($GPA >= 3.00)
            $result = "Pass with distinction";
       
        else if ($GPA >= 2.00)
            $result = "Pass";
           
        else
            $result = "Fail";
           
        return $result;
    }