Slip 7 - B) Consider the following relational database: Project (P_Group No, Project_Tiltle) Student (Seat_no, Name, Class, P_Group_No) Write an AJAX script to accept projecttitle and display list of students those who are working in a particular project.

 Solution:

slip7-p1-q2.html

<html>
<script type="text/javascript">
function display()
{
name=f1.txt.value;
var xmlhttp;
if(window.XMLHttpRequest)
{
xmlhttp= new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
        xmlhttp.open("GET", "slip7-p2-q2.php?txt="+ name,false);
        xmlhttp.send();
        document.getElementById('result').innerHTML=
        xmlhttp.responseText;
}
</script>
<body>
<form name="f1">
Enter Project_title:
<input type="text" name="txt" onKeyUp="display()"/><br>
</form>
<div id='result'></div> 
</body>
</html>

slip7-p2-q2.php

<?php
$host = "localhost";
$user = "root";
$password = "";
$dbname = "q3";

$con = mysqli_connect($host, $user, $password,$dbname);


if (!$con) {
  die("Connection failed: ".mysqli_connect_error());
}
?>
<html>
<head>
<style>
table 
{
  width: 100%;
  border-collapse: collapse;
}

table, td, th {
  border: 1px solid black;
  padding: 5px;
}

th {text-align: left;}
</style>
</head>
<body>
<?php
$q = $_GET['txt'];
mysqli_select_db($con,"q3");
$sql=("SELECT * FROM project7,student7 WHERE project7.p_group_no=student7.p_group_no and Project_title = '".$q."'");
$result = mysqli_query($con,$sql);

echo "<table>
<tr>
<th>Eid</th>
<th>Employeename</th>
<th>Designation</th>
<th>Contact Number</th>
</tr>";
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_array($result)) 
{
  echo "<tr>";
  echo "<td>" . $row['Seat_no'] . "</td>";
  echo "<td>" . $row['Name'] . "</td>";
  echo "<td>" . $row['Class'] . "</td>";
  echo "<td>" . $row['Project_title'] . "</td>";
  echo "</tr>";
}
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>


Post a Comment

0 Comments