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 )
);
ID | Name | subject | ClassesHeld | ClassesAttended | AttendancePercentage |
---|
1 | kumar | web | 40 | 10 | |
2 | ravi | cprogram | 40 | 36 | |
3 | raviraj | cprogram | 40 | 10 | |
4 | naveen | web | 40 | 2 | |
5 | nayana | cprogram | 40 | 5 | |
Calculate Percentage
ID | Name | subject | ClassesHeld | ClassesAttended | AttendancePercentage |
---|
1 | kumar | web | 40 | 10 | 25% |
2 | ravi | cprogram | 40 | 36 | 90% |
3 | raviraj | cprogram | 40 | 10 | 25% |
4 | naveen | web | 40 | 2 | 5% |
5 | nayana | cprogram | 40 | 5 | 12.5% |
List of student :shortage of Attendance
ID | Name | subject | AttendancePercentage | Shortage |
---|
3 | raviraj | cprogram | 25 | YES |
5 | nayana | cprogram | 13 | YES |
1 | kumar | web | 25 | YES |
4 | naveen | web | 5 | YES |
PAGE 1: program13.php
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.
< ?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 "
ID | Name | subject | ClassesHeld | ClassesAttended | AttendancePercentage |
";
// output data of each row
$table=array();
$i=0;
while($row = $result->fetch_assoc()) {
echo "".$row["Reg"]." | ".$row["name"].
" | ".$row["subject"].
" | ".$row["ClassesHeld"].
" | ".$row["ClassesAttended"].
" | ".$row["AttendancePercentage"]." |
";
$table[$i]=$row;
$i++;
}
echo "
";
echo "
Calculate Percentage
";
echo "ID | Name | subject | ClassesHeld | ClassesAttended | AttendancePercentage |
";
foreach ($table as $row){
$percent=($row["ClassesAttended"]/$row["ClassesHeld"])*100;
$row["AttendancePercentage"]=$percent;
echo "".$row["Reg"]." | ".$row["name"].
" | ".$row["subject"].
" | ".$row["ClassesHeld"].
" | ".$row["ClassesAttended"].
" | ".$row["AttendancePercentage"]."% |
";
$sql = "UPDATE studentattendance SET AttendancePercentage=".$percent." WHERE Reg=".$row["Reg"];
$conn->query($sql);
}
echo "
";
echo "
List of student :shortage of Attendance
";
$sql = "SELECT Reg,name,subject,AttendancePercentage FROM studentattendance order by subject";
$result = $conn->query($sql);
echo "
ID | Name | subject | AttendancePercentage | Shortage |
";
$i=0;
while($row = $result->fetch_assoc()) {
if($row["AttendancePercentage"]<70)
{
echo "".$row["Reg"]." | ".$row["name"].
" | ".$row["subject"].
" | ".$row["AttendancePercentage"].
" | ". " YES"." |
";
}
}
echo "
";
} else {
echo "0 results";
}
$conn->close();
?>