Showing posts with label if. Show all posts
Showing posts with label if. Show all posts

Monday, June 20, 2016

If Else Meeting 7

As a further lesson of "if" condition, now we learn on "if ... else " contion. In this lesson there are two choices and only one is fired. If the condition is "true" then the first statement is fired and if "false" the second statement is fired.
This is similar to the previous lesson but different. Pay attention and see the difference from the previous.

<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 >= 60){
print("<h3> $usrname is <font color=blue><b>"Passed"</b></font>
</h3>");
}
else {
print("<h3>
$usrname is <font color=red><b>"Not Passed"</b></font>
</h3>");
}
?>
</body>
</html>

save it as seven.php (this might overwrite the previous file unless you renamed it before save this file) and we still use six.php (in the previous lesson) file to call the form so that we can save time bu not recoding the first/origin file.

The login is, if condition is "true" then the statement in the first { } bracket is executed, if "false" the statement in the second { } bracket is executed.

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.

Tuesday, May 31, 2016

If Condition Meeting 6

Now we learn on "IF Ststement/Condition". In this example we still apply 2 files (pages) so that we can remember the previous lesson. Please pay attention to the single "if condition" below:

<html>

<head>
<title>Conditions</title>
</head>
<body>
<h3>IF Condition</h3>
<br>
Fill in a name and a exams mark[0-100] below:
<form action="seven.php" method="post">
<pre>
Nama : <input type="text" name="usrname" size="30" maxlength="30"><br><br>
Nilai : <input type="text" name="mark" size="3" maxlength="3"><br><br>
<input type="submit" value="Send Soon!">
</pre>
</form>
</body>
</html>

save the above file as six.php
Then create a script as a new file and save it as seven.php like below:

<html>
<head>
<title>Seven</title>
</head>
<body>
<h3>Thank you for entering your data</h3><br>
<h4>The marks result is:</h4>
<br>
<?php
$usrname = $_POST[usrname];
$mark = $_POST[mark];
$result = "Not Passed";
if ($mark >= 60){
$result = "Passed";
}
print("<h3>
$usrname is <font color=red><b>$result</b></font>
</h3>");

?>
</body>
</html>

Then open your browser and point to the six.php and see the result. It should show that the mark greater than or equal to 60 is "passed", if not it s "not passed".
The logic is, if the condition is "true" then the statement inside the { } bracket is executed if "false" it is not executed.