Thursday, June 9, 2016

If elseif Meeting 8

We still learn more on "if" condition. In this lesson we learn on multiple conditions "if ... elseif" . We have more than two choices but still only one is fired. The script will inspect, find and execute only the "true" condition.
We still use six.php (in meeting 6 as the first file to call) to be opened from your browser, and save this script below as seven.php (rename first the previous seven.php to another filename):

<html>
<head>
<title>Conditions - cont</title>
</head>
<body>
<h3>Thank you for entering your data</h3><br>
<h4>The marks result is:</h4>

<?php
$usrname = $_POST[usrname];
$mark = $_POST[mark];
if (($mark<=100)&& ($mark>90)){
print("<h3>
$usrname got <font color=#000000><b>"A"</b></font>
</h3>");
}
elseif (($mark<=90)&& ($mark>75)){
print("<h3>
$usrname got <font color=#0000ff><b>"B"</b></font>
</h3>");
}
elseif (($mark<=75)&& ($mark>60)){
print("<h3>
$usrname got <font color=#bb0000><b>"C"</b></font>
</h3>");
}
elseif (($mark<=60)&& ($mark>40)){
print("<h3>
$usrname got <font color=#ff0000><b>"D"</b></font>
</h3>");
}
elseif (($mark<=40)&& ($mark>=0)){
print("<h3>
$usrname was <font color=#ff0000>
<b><u>"Failed"</u></b></font>
</h3>");
}
else {
print("<h3>
<font color=##ff0000><b>"Invalid Data"</b></font>
</h3>");
}
?>
</body>
</html>

in the file above we also apply a little bit more complicated conditions with the hope that we can make a good progress on conditions. Try to call six.php from your browser and try some various inputs to submit and see the results.