PHP PROGRAMS || DATABASE || AJAX

PHP PROGRAMS




PHP PROGRAMS || DATABASE || AJAX





PHP DATABASE PROGRAM -


Q1) CONSIDER THE FOLLOWING ENTITIES AND THEIR RELETHIONSHIP.




--->

<html>
<body>
<form method="POST" action="Slip9_2.php">
Competition Name:<input type="text" name="comp"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
<html>


<?php
$cname=$_POST['comp'];

$con=pg_connect("host=localhost dbname=root user=root") or die("Could not connect");

$qry="selce * from Student where stud_id in(select stud_id from student_competition where c_no in(select c_no from competition where c_name=$cname) and rank=1);";

$rs=pg_query($con,$qry) or die("Unable to execute query");

if($rs!=null)
{
echo"<table border=0>";
echo"<tr><td>Stud_id</td><td>Name</td><td>Class</td></tr>";
while($row=pg_fetch_row($rs))
{
echo"<tr>";
echo"<td>".$row[0]."</td>";
echo"<td>".$row[1]."</td>";
echo"<td>".$row[2]."</td>";
echo"</tr>";
}
echo"</table>";
}
else
echo"NO records found";
pg_close($con);
?>


Q2) CONSIDER THE FOLLOWING ENTITIES AND THEIR RELATIONSHIP.



--->

<html>
<body>
<form method="POST" action="Slip11_2.php">
Department Name:<input type="text" name="dept"><br>
<input type="submit" name="submit" value="Submit">
</body>
</html>


<?php
$dept=$_POST['dept'];

$con=pg_connect("host=localhost dbname=root user=root")or die("Unable to connect");

$qry1="select max(salary) from Emp where d_no=(select d_no from dept where dname=$dept);";

$qry2="select min(salary) from Emp where d_no=(select d_no from dept where dname=$dept);";

$qry3="select sum(salary) from Emp where d_no=(select d_no from dept where dname=$dept);";

$rs1=pg_query($con,$qry1) or die("Unable to execute query");
$row1=pg_fetch_row($rs1);

$rs2=pg_query($con,$qry2) or die("Unable to execute query");
$row2=pg_fetch_row($rs2);

$rs3=pg_query($con,$qry3) or die("Unable to execute query");
$row3=pg_fetch_row($rs3);

if($rs1!=null && $rs2!=null && $rs3!=null)
{
echo"<table border=1>";
echo"<tr>";
echo"<td>Maximum Salary</td>";
echo"<td>Minimum Salary</td>";
echo"<td>Sum Salary</td>";
echo"</tr>";
echo"<tr>";
echo"<td>".$row1[0]."</td>";
echo"<td>".$row2[0]."</td>";
echo"<td>".$row3[0]."</td>";
echo"</tr>";
echo"</table>";
}
pg_close($con);
?>


Q3)CONSIDER THE FOLLOWING ENTITIES AND THEIR RELATIONSHIP.




--->

<html>
<body>
<form method="POST" action="Slip13.php">
Hospital Name<input type="text" name="hosp"><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>


<?php
$hname=$_POST['hosp'];

$con=pg_connect("host=localhost dbname=root user=root")or die("Unable to connect");

$qry="select * from doctor where hosp_no in(select hosp_no from hospital where hname=$hname);";
$rs=pg_query($con,$qry);

if($rs!=null)
{
echo"<table border=1>";
echo"<tr><td>Doctor No</td><td>Name</td><td>Address</td><td>City</td><td>Area</td></tr>";
while($row=pg_fetch_row($rs))
{
echo"<tr>";
echo"<td>".$row[0]."</td>";
echo"<td>".$row[1]."</td>";
echo"<td>".$row[2]."</td>";
echo"<td>".$row[3]."</td>";
echo"<td>".$row[4]."</td>";
echo"</tr>";
}
echo"</table>";
}

pg_close($con);
?>


AJAX PROGRAMS -


Q1)WRITE A AJAX PROGRAM TO READ contact.dat FILE AND PRINT THE CONTENT 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 RECORDS IN contact.dat FILE ].
 
--->

contact.dat file

1 Sachin 020111111 9028282629 Myself
2 Sourabh 02022222 9970970127 Friend
3 Nana 020333333 9604968618 Student
--------------------------------------------------------------------------------------------------------------------------

<html>
<head>
<script type="text/javascript">
function displayContents()
{
var xmlHttp;
if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 && xmlHttp.status==200)
{
document.getElementById("myDiv").innerHTML = xmlHttp.responseText;
}
}
xmlHttp.open("POST","ajax_read.php",true);
xmlHttp.send();
}

</script>
</head>
<body>
<h2>After clicking the print button, contents will be displayed from contact.dat file</h2>
<div id="myDiv"></div>
<input type="button" onclick="displayContents()" value="Print"/>
 
</body>
</html>



<?php

//File name that is to be read
$fileName = 'contact.dat';

//Check if file exists
if(!file_exists($fileName))
die("File $fileName does not exists");

//Open file in read mode
$fp = fopen($fileName,'r');

//Create table header i.e column names
$response = '<table border="1"><thead><th>Sr.No</th><th>Name</th><th>Residence Number</th><th>Mobile Number</th><th>Context/Relation</th></thead>';

//Traverse the file line by line and put contents into array and explore the array
while(! feof($fp))
{
//Get the file contents line by line
$row = fgets($fp);

//Explode the line/row on the basis of space and create an array
$row = explode(' ',$row);

//Access the index array for details
$response.= "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td></tr>";
}

//Close the file which was opened.
fclose($fp);

//Print the output
echo $response;

?>



Q2) CONSIDER THE FOLLOWING ENTITIES AND  RELATIONSHIP.




---->

<html>
<head>
<script type="text/javascript">
function displayTeacherInfo()
{

var xmlHttp;

if(window.XMLHttpRequest)
xmlHttp = new XMLHttpRequest();
else
xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');

xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4 && xmlHttp.status==200)
{
document.getElementById("myDiv").innerHTML = xmlHttp.responseText;
}
}
var tno = document.getElementById("tno").value;
xmlHttp.open("GET","get_data.php?tno="+tno,true);
xmlHttp.send();
}
</script>
</head>
<body>
<h2>Please add Teacher Number in the textbox and press display button to get teacher information</h2>
<input type="text" name="tno" id="tno" value=""/>
<input type="button" onclick="displayTeacherInfo()" value="Print"/>
 <div id="myDiv"></div>
</body>
</html>



<?php

$tno = $_GET['tno'];
if($tno == '')
die("<b>Please enter Teacher No.!!!</b>");


$con=pg_connect("host=localhost dbname=root user=root") or die("Could not connect");



//Prepare Query
$sql       = "Select * from teacher where tno = '$tno'";

//Execute Query
$resultSet =pg_query($con,$qry) or die("Unable to execute query");

if($resultSet)
{
echo '<b>Teacher Information is :</b>';
$row = $row=pg_fetch_row($resultSet);
echo "<br>Teacher Number : $row[0]<br> Teacher Name : $row[1]<br>Subject : $row[2]<br>Research Area : $row[3]";
}
else
{
echo "<b>Sorry: There is no teacher information for teacher no. $tno!!!</b>";
?>



Q3)WRITE A AJAX PROGRAM TO SEARCH STUDENT NAME ACCORDING TO THE CHARACTER TYPED AND DISPLAY LIST USING ARRAY.


--->

<html>
<body>

<script type="text/javascript">
function display()
{

var x= new XMLHttpRequest();
var n= document.getElementById('n').value;
x.open("GET", "name.php?n="+n, true);
x.send( );
x.onreadystatechange = function()
{
if(x.readyState == 4 && x.status==200)
{
document.getElementById("show").innerHTML = x.responseText;
}
}
}
</script>
Search Box: <input type="text" name='n' id='n' onkeyup="display()"> <br>

<h1 id="show"> </h1>
</body>
</html>


<?php
$n=$_GET['n'];
$a=array();
$a[]="sachin";
$a[]="sanjay";
$a[]="ajay";

echo "List of Names=<br>";
foreach($a as $v)
{
$s=substr($v,0,strlen($n));
if($s===$n)
echo "$v<br>";
}
?>


Q4) WRITE AJAX PROGRAM TO PRINT MOVIE DETAILS BY SELECTING AN ACTOR'S NAME. CREATE TABLES MOVIES AND ACTOR WITH 1:M CARDINALITY AS FOLLOWS:

MOVIE (MNO,MNAME,RELEASE_YEAR)
ACTOR (ANO,ANAME)
(USE POSTGRESQL).

--->


<html> <body>

<script type="text/javascript">
function display()
{

var x= new XMLHttpRequest();
var n= document.getElementById('n').value;
x.open("GET", "actor.php?n="+n, true);
x.send( );
x.onreadystatechange = function()
{
if(x.readyState == 4 && x.status==200)
{
document.getElementById("show").innerHTML = x.responseText;
}
}
}
</script>
Actor Name: <input type="text" name='n' id='n'"> <br>
<button onclick="display()" > Print</button>

<h1 id="show"> </h1>
</body>
</html>



<?php
$aname=$_POST['aname'];

$con=pg_connect("host=localhost dbname=root user=root") or die("Could not connect");

$qry="select mname,release_year from movie,actor where movie.mno=actor.mno and aname=$aname";

$rs=pg_query($con,$qry) or die("Unable to execute query");

if($rs!=null)
{
echo"<table border=0>";
echo"<tr><td>Movie Name</td><td>Release Year</td></tr>";
while($row=pg_fetch_row($rs))
{
echo"<tr>";
echo"<td>".$row[0]."</td>";
echo"<td>".$row[1]."</td>";
echo"</tr>";
echo"</table>";
}
else
echo"NO records found";
pg_close($con);
?>


Post a Comment

1 Comments

  1. About 25% of winnings in a single day go to players who actively used the platform that day. That being said, the more player activity, the upper the share 코인카지노 share. You will find different progressive jackpots, including the largest ones – as an example, the Sisters of OZ Wowpot.

    ReplyDelete