Problems: 

# Let the following table stored in database. Write down the php code to calculate the display GPA in web browser. 2011

 Roll No Web Eng Marks
  101 85
 102 65
 103 22

# PHP turning a student mark to a grade using if elseif,  


Source Code:

<?php 
$server_name = "localhost:3308";
$db = "tufan"; 
$user_name = "root";
$pass = "";

//Create Connection
$conn = new mysqli($server_name,$user_name,$pass,$db);

//Check Connectio
if(!$conn){
die ("Database problem!!!");
}
else{
echo "Connection Ok";
echo "<br>";
}


//select data
$a="SELECT* FROM gpa";
$result = mysqli_query($conn,$a);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
// $roll= $row['Roll No'];
// echo $row['id'];
$Marks= $row['Web Eng Marks'];
if ($Marks=85) {
$b="A+";
}
}
}

$a="SELECT* FROM gpa";
$result = mysqli_query($conn,$a);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
// $roll= $row['Roll No'];
// echo $row['id'];
$Marks= $row['Web Eng Marks'];
if ($Marks=65) {
$c="B-";
}
}
}

$a="SELECT* FROM gpa";
$result = mysqli_query($conn,$a);
if(mysqli_num_rows($result)>0){
while($row = mysqli_fetch_assoc($result)){
// $roll= $row['Roll No'];
// echo $row['id'];
$Marks= $row['Web Eng Marks'];

if ($Marks=22) {
$d="F";
}
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table border="1">
<tr>
<th>Roll No</th>
<th>Web Eng Marks</th> 
<th>GPA</th>
</tr>

<tr>
<td>101</td>
<td>85</td>
<td><?php echo $b; ?></td>
</tr>

<tr>
<td>102</td>
<td>65</td>
<td><?php echo $c; ?></td>
</tr>

<tr>
<td>103</td>
<td>22</td>
<td><?php echo $d; ?></td>
</tr>
</table>
</body>
</html>

Screenshots of  source code(browser):

PHP Calculating GPA
PHP Calculating GPA
PHP Calculating GPA
PHP Calculating GPA
PHP Calculating GPA


Output of Browser:

Connectio Ok
 Roll No Web Eng Marks GPA
 101 85 A+
 102 65 B-
 103 22 F


Screenshots of output(Browser):

PHP Calculating GPA

Post a Comment

Previous Post Next Post