Search This Blog

Sunday, 23 January 2022

13. PHP Program to read data from MySQL table and Calculate attendance percentage

<!-- 13. PHP Program to read data from MySQL table and calculate attendance percentage -->
<html>
<head>
<title>Read data and update mysql table using php </title>
</head>
<body bgcolor=gray text=yellow>
<?php

$connection = mysql_connect("localhost", "root", ""); // Establish Connection with Server
$db = mysql_select_db("test", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from prog13", $connection);
echo "<h3>Student Attendance Details</h3>";
echo "<table border=3 cellspacing=5>";
echo"<tr><th>RegNo</th><th>StudentName</th><th>Subject</th><th>ClassesHeld</th><th>ClassesAttended</th><th>AttendancePercentage</th></tr>";
while ($row = mysql_fetch_array($query))
{
    echo "<tr><td>".$row['RegNo']."</td>";
    echo "<td>".$row['StudentName']."</td>";
    echo "<td>".$row['Subject']."</td>";
    echo "<td>".$row['ClassesHeld']."</td>";
    echo "<td>".$row['ClassesAttended']."</td>";
    echo "<td>".$row['AttendancePercentage']."</td></tr>";

    $reg=$row['RegNo'];
    $CH=$row['ClassesHeld'];
    $CA=$row['ClassesAttended'];
    $per=($CA/$CH)*100;
    
    //Query for updation with calculated percentage.
        $query1 = mysql_query("update prog13 set AttendancePercentage='".$per."'where RegNo='".$reg."';",$connection);
    //Query to reset AttendancePercentage to zero.
        //$query1 = mysql_query("update prog13 set AttendancePercentage=0 where RegNo='".$reg."';",$connection);
    
}
echo "<table border=3>";
echo "<br><b>MySQL table updated successfully.</b>";
//Query for inserting values in prog13 table.
        //$query1 = mysql_query("insert into prog13 values('123','abcd','sub1',20,16,0);",$connection);
mysql_close($connection); // Closing Connection with Server
?>
</body>
</html>

13. PHP Program to read data from MySQL table and Calculate attendance percentage.

<!-- 13. PHP Program to read data from MySQL table and calculate attendance percentage -->

<html>
<head>
<title>Read data and update mysql table using php </title>
</head>
<body bgcolor=gray text=yellow>
<?php

$connection = mysql_connect("localhost", "root", ""); // Establish Connection with Server
$db = mysql_select_db("test", $connection); // Selecting Database
//MySQL Query to read data
$query = mysql_query("select * from prog13", $connection);
echo "<h3>Student Attendance Details</h3>";
echo "<table border=3 cellspacing=5>";
echo"<tr><th>RegNo</th><th>StudentName</th><th>Subject</th><th>ClassesHeld</th><th>ClassesAttended</th><th>AttendancePercentage</th></tr>";
while ($row = mysql_fetch_array($query))
{
    echo "<tr><td>".$row['RegNo']."</td>";
    echo "<td>".$row['StudentName']."</td>";
    echo "<td>".$row['Subject']."</td>";
    echo "<td>".$row['ClassesHeld']."</td>";
    echo "<td>".$row['ClassesAttended']."</td>";
    echo "<td>".$row['AttendancePercentage']."</td></tr>";

    $reg=$row['RegNo'];
    $CH=$row['ClassesHeld'];
    $CA=$row['ClassesAttended'];
    $per=($CA/$CH)*100;
    
    //Query for updation with calculated percentage.
        $query1 = mysql_query("update prog13 set AttendancePercentage='".$per."'where RegNo='".$reg."';",$connection);
    //Query to reset AttendancePercentage to zero.
        //$query1 = mysql_query("update prog13 set AttendancePercentage=0 where RegNo='".$reg."';",$connection);
    
}
echo "<table border=3>";
echo "<br><b>MySQL table updated successfully.</b>";
//Query for inserting values in prog13 table.
        //$query1 = mysql_query("insert into prog13 values('123','abcd','sub1',20,16,0);",$connection);
mysql_close($connection); // Closing Connection with Server
?>
</body>
</html>

12. PHP Program to read text file and display data using TABLE tag.

 <!-- 12. PHP Program to read text file and display data using <table> tag. -->
<html>

   <head>
      <title>Reading a file using PHP</title>
   </head>
   <?php
        // Turn off all error reporting
    error_reporting(0);
    ?>

    <body bgcolor=green text=white>
      
    <?php
           $fp = fopen('D:\\php.txt', 'r');
         
         if( $fp == false )
         {
            echo ( "<h3>File not found!</h3>" );
            exit();
         }
         
           $delimiter='#';

            echo "<h3>Salary Details of Employees:</h3>";
            print_r("<table border=3>");
            print_r("<tr><th>EmpId</th><th>EmployeeName</th><th>Designation</th><th>Department</th>
            <th>BasicSalary</th><th>Allowance</th><th>Deduction</th><th>GrossSalary</th><th>NetSalary</th></tr>");
            while ( !feof($fp) )
            {
                $line = fgets($fp, 1024);

                $data = str_getcsv($line, $delimiter);
                   
                $eid=$data[0];
                $ename=$data[1];
                $desig=$data[2];
                $dept=$data[3];
                $bsal=$data[4];
                $all=$data[5];
                $ded=$data[6];
                $gsal=$bsal+$all;
                $nsal=$gsal-$ded;
                print_r("<tr>");
                print_r("<td>".$eid. "</td>");
                print_r("<td>".$ename. "</td>");
                print_r("<td>".$desig. "</td>");
                print_r("<td>".$dept. "</td>");
                print_r("<td>".$bsal. "</td>");
                print_r("<td>".$all. "</td>");
                print_r("<td>".$ded. "</td>");
                print_r("<td>".$gsal. "</td>");
                print_r("<td>".$nsal. "</td>");
                echo "</tr>";
            }              
            echo "</table>";
      ?>
      
   </body>
</html>

12. PHP Program to Read text file and Display data using TABLE tag.

 <!-- 12. PHP Program to read text file and display data using <table> tag. -->
<html>

   <head>
      <title>Reading a file using PHP</title>
   </head>
   <?php
        // Turn off all error reporting
    error_reporting(0);
    ?>

    <body bgcolor=green text=white>
      
    <?php
           $fp = fopen('D:\\php.txt', 'r');
         
         if( $fp == false )
         {
            echo ( "<h3>File not found!</h3>" );
            exit();
         }
         
           $delimiter='#';

            echo "<h3>Salary Details of Employees:</h3>";
            print_r("<table border=3>");
            print_r("<tr><th>EmpId</th><th>EmployeeName</th><th>Designation</th><th>Department</th>
            <th>BasicSalary</th><th>Allowance</th><th>Deduction</th><th>GrossSalary</th><th>NetSalary</th></tr>");
            while ( !feof($fp) )
            {
                $line = fgets($fp, 1024);

                $data = str_getcsv($line, $delimiter);
                   
                $eid=$data[0];
                $ename=$data[1];
                $desig=$data[2];
                $dept=$data[3];
                $bsal=$data[4];
                $all=$data[5];
                $ded=$data[6];
                $gsal=$bsal+$all;
                $nsal=$gsal-$ded;
                print_r("<tr>");
                print_r("<td>".$eid. "</td>");
                print_r("<td>".$ename. "</td>");
                print_r("<td>".$desig. "</td>");
                print_r("<td>".$dept. "</td>");
                print_r("<td>".$bsal. "</td>");
                print_r("<td>".$all. "</td>");
                print_r("<td>".$ded. "</td>");
                print_r("<td>".$gsal. "</td>");
                print_r("<td>".$nsal. "</td>");
                echo "</tr>";
            }              
            echo "</table>";
      ?>
      
   </body>
</html>

11. JavaScript Program to Display Student Placement Details Course-wise.

 <!-- 11. JavaScript Program to display student placement details course-wise. -->
<html>
<head>
<title>Placement Program11</title>
<script language="JavaScript">
var regno=document.getElementsByName("regno[]");
var sname=document.getElementsByName("sname[]");
var bca=new Array();
var bsc=new Array();
var bcom=new Array();
var b1="BCA:<br>";
var s1="BSc:<br>";
var c1="BCom:<br>";
var bc=0;
var sc=0;
var cc=0;
function find()
{
    for (var i = 0; i < regno.length; i++)
    {
    
        var a = regno[i];
        var b = sname[i];
              
        if(a.value.charAt(0)=='B' || a.value.charAt(0)=='b')
        {
            bca[i]="Register Number:"+a.value+"     Name:"+b.value+"<br>";
                b1=b1 + bca[i];
                bc++;
        }
        if(a.value.charAt(0)=='S' || a.value.charAt(0)=='s')
        {
            bsc[i]="Register Number:"+a.value+" Name:"+b.value+"<br>";
                s1=s1 + bsc[i];
                sc++;
        }
        if(a.value.charAt(0)=='C' || a.value.charAt(0)=='c')
        {
            bcom[i]="Register Number:"+a.value+" Name:"+b.value+"<br>";
                c1=c1 + bcom[i];
                cc++;
        }
}
    document.getElementById("heading").innerHTML="List of Students belonging to each Course:"
    document.getElementById("bca1").innerHTML = b1;
    document.getElementById("bca2").innerHTML = "Total Students selected from BCA:"+bc;
    document.getElementById("bsc1").innerHTML = s1;
    document.getElementById("bsc2").innerHTML = "Total Students selected from BSc:"+sc;
    document.getElementById("bcom1").innerHTML = c1;
    document.getElementById("bcom2").innerHTML = "Total Students selected from BCom:"+cc;
    
    }
</script>
</head>
<body bgcolor=gray text=yellow>
<form method=get>
<table border=3 >
<tr><th colspan=3>Students Short-listed in Placement</th></tr>
<tr><th>S.No.</th><th>Register Number</th><th>Student Name</th></tr>
<tr><td>01.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>02.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>03.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>04.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>05.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>06.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>07.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>08.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>09.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>10.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>11.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>12.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>13.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>14.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>15.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>16.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>17.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>18.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>19.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td>20.</td><td><input type=text name=regno[]></td><td><input type=text name=sname[]></td></tr>
<tr><td colspan=3 align=center><input type=button value=Submit onClick="find()"></td></tr>
</table>
</form>
<h2 id="heading"></h2>
<h3 id="bca1" ></h3>
<h3 id="bca2"></h3>
<h3 id="bsc1"></h3>
<h3 id="bsc2"></h3>
<h3 id="bcom1"></h3>
<h3 id="bcom2"></h3>
</body>
</html>

FREE Hit Counters