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>

Friday 7 January 2022

10. HTML program to read registration details & JSP program to generate OTP and check for registration.

 <!--  10. HTML program to read registration details. -->

<html>

<head>

<title>OTP Form</title>

</head>

<body bgcolor=gray text=yellow>

 

<form action="Prog10.jsp">

<table border=3>

<tr><td>Student Name:</td><td><input type=text name=sname></td></tr>

<tr><td>Email ID:</td><td><input type=text name=email></td></tr>

<tr><td>Date of Birth:</td><td><input type=text name=dob></td></tr>

</table>

<script language="JavaScript">

function check()

{

     var str1=document.forms[0].elements[2].value;

     var result = str1.substring(10, 6);

     if(result>2003)

          alert("Age should be greater than 18 years!");

     else

          alert("Click on Submit")

}

</script>

<input type=button value=Proceed onClick="check()" name=Proceed>

<input type=submit value=Submit>

<input type=Reset value=Clear>

</form>

 

</body>

</html>

<!--  10. JSP program to generate OTP and check for registration. -->

<html>

<head>

<%@page import="java.io.*,java.util.*,java.text.SimpleDateFormat"%>

<title>OTP Generation</title>

 

</head>

<body bgcolor=gray text=yellow>

Date and Time:

<%

SimpleDateFormat dt = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");

String date = dt.format(new Date());

out.println(date);

String sname=request.getParameter("sname");

String email=request.getParameter("email");

String dob=request.getParameter("dob");

//String otp=request.getParameter("otp1");

//out.println(otp);

%>

 

<table border=3>

<tr><th>StudentName:</th><th><%=sname %></th></tr>

<tr><td>Email ID:</td><td><%=email %></td></tr>

<tr><td>Date of Birth:</td><td><%=dob %></td></tr>

</table>

 

<form>

<input type=button value=GetOTP onClick="OTP()">

<input type=button value=Submit >

</form>

<script language="JavaScript">

var otp;

function OTP()

{

     var otp=Math.floor(Math.random() * 10000) + 1;

     alert(otp);

     var otp1=prompt("Enter the OTP");

     if(otp1==otp)

          document.write("<font color=green >Registration Success!</font>");

     else

          document.write("<font color=red >OTP Mismatch!</font>");

}

 </script>

</body>

</html>

9. JSP Program to read registration details and write into text file & JSP program to read details from text file and show in tabular format.

 <!-- 9. JSP program to read registration details and write into text file. -->

<html>

<head>

<%@page import="java.io.*,java.lang.*,java.util.Scanner;" %>

<%! int flag=0; %>

<title>Program9 to Write File</title>

 

</head>

<body bgcolor=gray text=yellow>

<h3>Workshop Registration Form</h3>

<form action="Prog9.jsp" name="form1">

<table border=3>

<tr><td>Sl.No.:</td><td><input type=text name=sno></td></tr>

<tr><td>Delegate Name:</td><td><input type=text name=dname></td></tr>

<tr><td>College Name:</td><td><input type=text name=cname></td></tr>

<tr><td>Delegate Type:</td><td><select name=dtype><option>Staff</option><option>Student</option></select></td></tr>

<tr><td>Address:</td><td><textarea name=address></textarea></td></tr>

<tr><td>Phone Number:</td><td><input type=text name=phone></td></tr>

</table>

<input type=submit value=SAVE>

</form>

<form action="Prog91.jsp" name="form2">

<input type=submit value=DISPLAY>

</form>

<%

    

          String sno=request.getParameter("sno");

          String dname=request.getParameter("dname");

          String cname=request.getParameter("cname");

          String dtype=request.getParameter("dtype");

          String address=request.getParameter("address");

          String phone=request.getParameter("phone");

         

          try

          {

     BufferedReader reader = new BufferedReader(new FileReader("D:\\example.txt"));

   

               File fileObj = new File("D:\\example.txt");

               FileWriter fstream1 = new FileWriter(fileObj, true);

               BufferedWriter br = new BufferedWriter(fstream1);

                   

               if(flag==0) //Check for first time entry in the file.

               {

                  br.write("Sl.No"+"#"+"DelegateName"+"#"+"College"+"#"+"DelegateType"+"#"+"Address"+"#"+"Phone"+"#");

                   flag=1;  //File heading is written.

                   br.newLine();

               }

               if(dname!=null)

               {

                   br.write(sno+"#"+dname+"#"+cname+"#"+dtype+"#"+address+"#"+phone+"#");

                   br.newLine();

               }

              br.close();   //close buffer writer

       }

      catch(Exception e){out.println("Enter Valid Input!");}

  %>

</body>

</html>

<!-- 91. JSP program to read details from text file and show in tabular format. -->

<html>

<head>

<%@page import="java.io.*,java.lang.*,java.util.Scanner;" %>

<title>Read File</title>

</head>

<body  bgcolor=gray text=yellow>

<%

     try

     {

         File fileObj = new File("D:\\example.txt");

         Scanner scanObj = new Scanner(fileObj);

         out.println("<h3>Details of Delegates:</h3>");

         out.println("<table cellpadding=2 border=3>");

         while (scanObj.hasNextLine())

         {

                String line = scanObj.nextLine();

                String str[]=line.split("#",7);

                out.println("<tr>");

                for (String s :str)

                {

                     out.println("<td>"+s+"</td>");

                }

                   out.println("</tr>");

         }

         out.println("</table>");

         scanObj.close();

     }

     catch (Exception e)

     {

         out.println("Enter Valid Input!");

         //out.println(e);

      }

    %>

</body>

</html>

FREE Hit Counters