Friday, 29 April 2016
Saturday, 23 April 2016
Week 8
This week we learned on PHP and form processing. PHP is good at handling data submitted to the server in HTML forms. Form is used to accept user input in a systematic and structured manner. There are two main attributes in a form which are method and action.
1. $_POST
Form processing with $_POST- welcome.html
welcome.html with POST method |
output |
Displaying Submitted Values- welcome.php
welcome.php with POST method |
output |
2. $_GET
Form processing with $_GET- welcome.html
welcome.html with method GET |
output |
Displaying Submitted Values- welcome.php
welcome.php with GET method |
output |
3. $_REQUEST variable: it contains contents both $_GET, $_POST and $_COOKIE. It can be used to get the result from form data sent with both the GET and POST methods.
For the lab session
We have done some discussion on past year question regarding to processing CGPA.Click to visit the link.
//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;
}
//to print output of the name and matric
Name: <?php echo $_POST["name"]; ?><br>
Matric: <?php echo $_POST["matric"];?>
//to display output in a Table format
<table width = "100%" border="1" cellspacing="2" cellpadding="2">
<tr>
<th align="left">Course Code</th>
<th align="left">Course Name</th>
<th align="center">Credits</th>
<th align="center">Marks</th>
<th align="center">Gred</th>
<th align="center">Point</th>
</tr>
<tr>
<td>STIV1023</td>
<td>Multimedia Foundation</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv1023_mark;?></td>
<td align="center"><?php echo $stiv1023_gred;?></td>
<td align="center"><?php echo $stiv1023_point;?></td>
</tr>
<tr>
<td>STIV2023</td>
<td>Graphic & Animation</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv2023_mark;?></td>
<td align="center"><?php echo $stiv2023_gred;?></td>
<td align="center"><?php echo $stiv2023_point;?></td>
</tr>
<tr>
<td>STIV3013</td>
<td>WWW Programming</td>
<td align="center">3</td>
<td align="center"><?php echo $stiv3013_mark;?></td>
<td align="center"><?php echo $stiv3013_gred;?></td>
<td align="center"><?php echo $stiv3013_point;?></td>
</tr>
<tr>
<td>VKHB2031</td>
<td>Kelana Siswa</td>
<td align="center">1</td>
<td align="center"><?php echo $vkhb2031_mark;?></td>
<td align="center"><?php echo $vkhb2031_gred;?></td>
<td align="center"><?php echo $vkhb2031_point;?></td>
</tr>
</table><br/>
<p>Total Credit: 10<br/>
Gred Point Average(GPA) = <?php echo $GPA;?><br/>
Result : <?php echo $result;?></p>
output |
Friday, 8 April 2016
Week 7
We had a discussion on the previous lab test exercise. We also done extra exercise about the BMI calculator.
if ($BMI>= 30)
echo "obes";
elseif ($BMI>= 25)
echo "overweight";
elseif ($BMI>= 18.5)
echo "normal";
else
echo "underweight";
The is no lab class for this week.
if ($BMI>= 30)
echo "obes";
elseif ($BMI>= 25)
echo "overweight";
elseif ($BMI>= 18.5)
echo "normal";
else
echo "underweight";
The is no lab class for this week.
Friday, 1 April 2016
Week 6
For week 6, we learned about PHP which is one of the server-side script language. PHP scripts can be embedded within HTML to create dynamic and interactive web pages. PHP is an open source, easy to use, can be installed in multiple platforms and database supported.
PHP Basic Syntax
<?php PHP code goes here ?>
<? PHP code goes here ?>
<script language=“php”
PHP
code goes here </script>
PHP basics include:
1. Variables and Data Types - must begin with a $
- they are case sensitive
- Loosely typed language. It can be a number(integer/floating point) or a string of text or Boolean values.
Comparison Operators |
Arithmetic Operators |
Logical Operators |
3. Conditional Statements and Loops
- if statement
- if-else and elseif statement
- switch statement
- for loop
- while loop
- do-while loop
4. Functions
- A function is a piece of PHP code that perform a useful task, and usually return a value related to that task.
- it can be executed once or many times by the PHP script.
- An array is a variable that can contain multiple values under a single variable name.
- It is useful for storing a group of related values.
For the lab session
We have done some exercises on the PHP topic.
Subscribe to:
Posts (Atom)