Saturday, May 19, 2012

Program name: write a PHP script: Given a flat file of student information student no, name, mark I, mark II, mark III. Read this file and print the mark list in tabular form. Mark list will contain Student no, Name, Mark I, Mark II, Mark III and percentage for all students(PHP)


<?php

if(file_exists("stud_1.dat"))
{
$fp = fopen("stud_1.dat","r");

if(!$fp)
echo "File opening Error";
else
{
$buf = fread($fp,filesize("stud_1.dat"));
$tempercs = explode("\n",$buf);
$i = 0;

       //echo $buf;
foreach($tempercs as $t)
if(strlen($t)>0)
$records[$i++] = explode(" ",$t);

echo "<p>************* Student Name ***************</p>";
echo "<table border=2>";
echo "<tr><th> Roll No </th><th> Name </th>
<th> Mark I </th>
<th> Mark II </th>
<th> Mark III </th>
<th> Percentage </th></tr>";



foreach($records as $rec)
{
//print_r($rec);
echo "<tr>";
$k = 1;
$tot = 0;
foreach($rec as $f)
{
printf("<td>%s</td>",$f);
$k++;


if($k>3)
$tot = $tot + $f;
}
$ptage = ($tot/3.0);
printf("<td>%2f</td></tr>",$ptage);
}
echo "<table>";
fclose($fp);
}

}
else
{
echo "Not Exist";
}
?>



No comments:

Post a Comment