Q2.
Consider the following entities and their relationships
Event (eno , title , date )
Committee ( cno , name, head , from_time ,to_time , status)
Event and Committee have many to many relationship. Write a script to accept title of event
and modify status committee as working.
Answer:-
Php:-
<?php
$c=pg_connect("host=192.168.100.252 dbname=tydb3 user=ty3");
if(!$c)
echo 'not connected';
else
echo "done \n";
$e=$_GET['t1'];
$q=pg_query("update comm set status ='not done' where cno in (select cno
from e_c where eno
in (select eno from event where title='0'));");
if(!$q)
echo "not updated";
else
echo "\n updated!";
?>
Html:-
<!DOCTYPE html>
<html>
<head><title>Assign 6 set a q1</title></head>
<body>
<form name=f1 method=get action=http://192.168.100.252/ty2/ass6a1.php>
Enter title: <input type=text name=t1>
<input type=submit value=Update>
</form>
</body>
</html>
------------------------------------------------------------------------------------------------------------
---------------
Q2) Considerer the following entities and their relationships
Student (Stud_id,name,class)
Competition (c_no,c_name,type)
Relationship between student and competition is many-many with attribute rank and year.
Create a RDB in 3NF for the above and solve the following. Using above database write a
script in PHP to accept a competition name from user and display information of student who
has secured 1st rank in that competition.
Answer:-
StudCom.html
<html>
<body>
<form method="get" action="studcomp.php">
<fieldset>
<legend>Enter Competition Name :</legend><br>
<input type="text" name="cnm"><br><br>
</fieldset>
<div align="center">
<input type="submit" value="Show Result">
</div>
</form>
</body>
</html>
StudCom.php
<?php
$cnames=$_GET['cnm'];
$hn="localhost";
$un="root";
$pass="";
$db="students";
$link=mysqli_connect($hn,$un,$pass,$db);
if(!$link)
{
die('Connection Failed:'.mysqli_error());
}
//$sql="SELECT * FROM student WHERE CNo IN (SELECT CNo FROM
competition WHERE CName = '".$cname."')";
$sql="select * from student,competition,studcomp where
student.Sid=studcomp.Sid and competition.CNo=studcomp.CNo and rank='1'
and CName='".$cnames."'";
$res=mysqli_query($link,$sql);
if(mysqli_num_rows($res)>0)
{
while($row=mysqli_fetch_assoc($res))
{
echo"Stud No : ".$row['Sid']."<br>"." Name : ".
$row['SName']."<br>";
echo"Class : ".$row['SClass']."<br>";
echo"--------------------------"."<br>";
}
}
else
{
echo"error";
}
mysqli_close($link);
?>
------------------------------------------------------------------------------------------------------------
---------------
Q 2. Property (pno, description, area)
a. Owner (oname, address, phone)
b. An owner can have one or more properties, but a property belongs to exactly one owner.
c. Accept owner name from the user. Write a PHP script which will display all properties which
are own by that owner
Answers:-
<!DOCTYPE html>
<html>
<head><title>Assign 6 set b q1</title></head>
<body>
<form name=f1 method=get action=http://192.168.100.252/ty2/ass6b1.php>
Enter name: <input type=text name=t1>
<input type=submit value=Show>
</form>
</body>
</html>
<?php
$c=pg_connect("host=192.168.100.252 dbname=tydb2 user=ty2");
if(!$c)
echo "not connected";
else
echo "done";
$t=$_GET['t1'];
$q=pg_query("select * from property where oname='".$t."';");
while($rs=pg_fetch_array($q))
{
echo "<br>Name: ".$rs[3]."<br>Property: ".$rs[1];
echo "<br>-----------";
}
?>