BCA

WEB PROGRAMMING LAB

PROGRAM 1 PROGRAM 2 PROGRAM 3 PROGRAM 4 PROGRAM 5 PROGRAM 6

PART B

PROGRAM 7 PROGRAM 8 PROGRAM 9 PROGRAM 10 PROGRAM 11 PROGRAM 12 PROGRAM 13 PROGRAM 14 PROGRAM 15 . . .

OUTPUT: Question:
  • a)Read data from StudentAttendance table
  • b) calculates the percentage of classes that the student has attended
  • c)displays the subjectwise shortage of attendance list.
  • d)After calculating the percentage, the table needs to be updated with the calculated value.

database: mytestdb mysql table:
CREATE TABLE studentplacement ( registernumber int(10), name varchar(50), course varchar(50), placememntmode varchar(50), employertype varchar(50), selectiondate varchar(50), package varchar(50), PRIMARY KEY (id ) );
IDName subject ClassesHeld ClassesAttended AttendancePercentage
1kumar web 40 10
2ravi cprogram 40 36
3raviraj cprogram 40 10
4naveen web 40 2
5nayana cprogram 40 5

Calculate Percentage


IDName subject ClassesHeld ClassesAttended AttendancePercentage
1kumar web 40 10 25%
2ravi cprogram 40 36 90%
3raviraj cprogram 40 10 25%
4naveen web 40 2 5%
5nayana cprogram 40 5 12.5%

List of student :shortage of Attendance


IDName subject AttendancePercentage Shortage
3raviraj cprogram 25 YES
5nayana cprogram 13 YES
1kumar web 25 YES
4naveen web 5 YES

PAGE 1: program13.php

 
 

  Question:
 <ul>
<li>a)Read data from StudentAttendance table</li><li>
        b) calculates the percentage of classes that the student has attended</li><li>   
        c)displays the subjectwise shortage of attendance list.</li><li>
        d)After calculating the percentage, the table needs to be updated with the calculated value.</li></ul>
<style>
table {
  border-collapse: collapse;
  width: 50%;
}

th, td {
  text-align: left;
  padding: 8px;
}

tr:nth-child(even){background-color: #f2f2f2}

th {
  background-color: #04AA6D;
  color: white;
}
</style>
< ?php
$servername = "localhost";
$username = "root";
$password = "12345678";
$dbname = "mytestdb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

//Table name is =studentattendance
///reg, name, subject ,ClassesHeld	,ClassesAttended,	AttendancePercentage 
	
$sql = "SELECT Reg,name,subject,ClassesHeld,ClassesAttended FROM studentattendance  ";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
  echo "<hr><table><tr><th>ID</th><th>Name</th>  <th>subject</th>  <th>ClassesHeld</th>  <th>ClassesAttended</th>  <th>AttendancePercentage</th></tr>";
  // output data of each row


$table=array();
$i=0;
  while($row = $result->fetch_assoc()) {
    echo "<tr><td>".$row["Reg"]."</td><td>".$row["name"].
                                " </td><td>".$row["subject"].
                                " </td><td>".$row["ClassesHeld"].
                                " </td><td>".$row["ClassesAttended"].
                                 " </td><td>".$row["AttendancePercentage"]."</td></tr>";

    $table[$i]=$row;
    $i++;
  }
  echo "</table>";
 

  echo "<hr><h1>Calculate Percentage </h1><hr>";
 echo "<table><tr><th>ID</th><th>Name</th>  <th>subject</th>  <th>ClassesHeld</th>  <th>ClassesAttended</th>  <th>AttendancePercentage</th></tr>";
 foreach ($table as $row){

        $percent=($row["ClassesAttended"]/$row["ClassesHeld"])*100;

        $row["AttendancePercentage"]=$percent;

 echo "<tr><td>".$row["Reg"]."</td><td>".$row["name"].
                                " </td><td>".$row["subject"].
                                " </td><td>".$row["ClassesHeld"].
                                " </td><td>".$row["ClassesAttended"].
                                 " </td><td>".$row["AttendancePercentage"]."%</td></tr>";

            $sql = "UPDATE studentattendance SET AttendancePercentage=".$percent." WHERE Reg=".$row["Reg"];

                $conn->query($sql);
        
    }
 echo "</table>";

echo "<hr><h1>List of student :shortage of Attendance</h1>";


$sql = "SELECT Reg,name,subject,AttendancePercentage FROM studentattendance order by subject";
$result = $conn->query($sql);
 echo "<hr><table><tr><th>ID</th><th>Name</th>  <th>subject</th>    <th>AttendancePercentage</th> <th>Shortage</th> </tr>";
   
$i=0;
  while($row = $result->fetch_assoc()) {
 if($row["AttendancePercentage"]<70)
{
    echo "<tr><td>".$row["Reg"]."</td><td>".$row["name"].
                                " </td><td>".$row["subject"].
                                " </td><td>".$row["AttendancePercentage"].
                                " </td><td>". " YES"."</td></tr>";
}
    
    
  }
  echo "</table>";


} else {
  echo "0 results";
}

$conn->close();
?>