TY_BCS_PHP_SLIP 14_2



Slip no 14. Write a AJAX program to read contact. Dat file and print the contain of a file in a Tabular form when the user clicks on print button.
Contact.dat file contain srno, name, residence number, mobile number, context/ relation.
[ Enter at least 3 record in contact.dat file]
[Note: Examinar may change the contact. dat, dept.dat and provide proper structure of the file]
HTML file :
<html>
<head>
<style>
span
{
                font-size: 25px;
}
table
{
                color: blueviolet; ;
}
</style>

<script type="text/javascript" >
                function print()
                {
                                var ob=false;
                                ob=new XMLHttpRequest();
               
                                ob.open("GET","slip14_Q2.php?");//emailid="+eid);
                                ob.send();          
               
                                ob.onreadystatechange=function()
                                {
                                                if(ob.readyState==4 && ob.status==200)
                                                {
                                                                document.getElementById("i").innerHTML=ob.responseText; 
                                                }
                                }
                }             
</script>
</head>

<body>
<center>
<h3>Display the contents of a contact.dat file </h3>
<br><input  type="button"  value=Print onclick="print()" >
<span id="i"></span>
</center>
</body>
</html>

Dat file : contact.dat
1  Isha  65768798  98765432  Daughter
2  Megha  65235689  87654329  Mother

PHP file :
<?php
                $fp = fopen('contact.dat','r');
                echo "<table border=1>";
                echo "<tr><th>Sr. No.</th><th>Name</th><th>Residence No.</th><th>Mob. no.</th><th>Relation</th></tr>";
               
while($row =  fscanf($fp,"%s %s %s %s %s"))
                {
                                echo "<tr>";
                                foreach($row as $r)
                                {
                                                echo "<td>$r</td>";                            
                                }                             
                                echo "</tr>";
                }
                                echo "</table>";
                fclose($fp);
?>

No comments:

Post a comment

Note: only a member of this blog may post a comment.