Consider the following entities and their relationships
student (sno integer, s_name char(30), s_class char(10), s_addr char(50))
teacher (tno integer, t_name char (20), qualification char (15),experience integer)
The relationship between student-teacher: m-m with descriptive attribute subject.
Using above database write a script in PHP to accept a teacher name from user
and display the names of students along with subjects to whom teacher is teaching
ex5setb2.html
<html>
<body>
<form method="post" action="ex5setb2.php">
Enter teacher name:
<input type="text" name="tname"><br>
<input type='submit' name='submit' value='submit'>
<input type='reset' name='reset' value='reset'>
</form>
</body>
</html>
ex5setb2.php
<?php
$str1=$_POST['tname'];
$conn_str="host=192.168.100.10 port=5432 dbname=tybcs8 user=tybcs8";
$conn=pg_connect("$conn_str");
if(!$conn)
{
echo"fail";
}
else
{
$q="select teacher.tname, student.sname,s_t.subject from student,teacher,s_t where student.sno=s_t.sno and teacher.tno=s_t.tno and tname='$str1'";
$rs=pg_query($conn,"$q");
if(!$rs)
{
echo" an error<br>";
}
echo"<table border=2>";
echo"<tr>";
echo"<th>Teacher name</th>";
echo"<th>Student name</th>";
echo"<th>Subject</th>";
echo"</tr>";
while($row=pg_fetch_assoc($rs))
{
echo"<tr>";
echo"<td>$row[tname]</td>";
echo"<td>$row[sname]</td>";
echo"<td>$row[subject]</td>";
echo"</tr>";
}
echo"</table>";
}
?>
0 Comments
If anyone has Doubts or suggestions please let me know