In order to become familiar with PHP programming structures and commands, we will build various PHP pages.S Sections of this page will explain each PHP command, provide a link to a working sample, and detail the working sample's PHP code. Let's get started:
<html>
<head>
<title>ifstatements.php</title>
</head>
<body>
My Web 2 students have just taken their final exam.
It was very difficult so I decided to buy my 'A' students a new car.
Here are their scores:
Justin 89.4
Alicia 89
Manuel 90
Raul 91
Toni 89.3
Griselda 92
Granias 99
Jose 99.9
Let's use PHP to display the great news to each
student based on their exam result.
<?php
//These are variables to hold the grades
$justinsgrade=89.4;
$aliciasgrade= 89;
$manuelsgrade= 90;
$raulsgrade=91;
$tonisgrade=89.3;
$griseldasgrade=92;
$grainasgrade=99;
$josesgrade=99.9;
//Here are the if statements to test
//whether students scored greater than 89.5 (I round up).
if ($justinsgrade >= 90)
{
print("Justin, you get a new car! A van.<br>");
}
if ($aliciasgrade >= 90)
{
print("Alicia, you get a new car! A bug.<br>");
}
if ($manuelsgrade >=90)
{
print("Manuel, you get a new car! A truck.<br>");
}
if ($raulssgrade >= 90)
{
print("Raul, you get a new car! A sports car.<br>");
}
if ($tonisgrade >= 90)
{
print("Toni, you get a new car! A station wagon. <br>");
}
if ($griseldasgrade >= 90)
{
print("Griselda, you get a new car! An RV. <br>");
}
if ($grainasgrade >= 90)
{
print("Grainas, you get a new car! A mini-van. <br>");
}
if ($josesgrade >= 90)
{
print("Jose, you get a new car! A sports car. <br&g;t");
}
?>
</body>
</html>