Wednesday, 27 December 2017

AWT-Slip13

1)Write a PHP script using AJAX concept, to develop user-friendly and interactive search engine (like a google search engine)                                                                                    

fetch.html

 <html>

<head>

<script>

function showMatch(str)

{            

if (str.length==0)

{

document.getElementById("mydiv").innerHTML = "";

return;

}

if(window.XMLHttpRequest)

{

XHRobj=new XMLHttpRequest();

}

else

{

XHRobj=new ActiveXObject("Microsoft.XMLHTTP");

}

XHRobj.onreadystatechange = function()

{

if (XHRobj.readyState == 4 && XHRobj.status == 200)

{

document.getElementById("mydiv").innerHTML = XHRobj.responseText;

}

}

XHRobj.open("GET", "fetch.php?q=" +str, true);

XHRobj.send();

}

</script>

</head>

<body>

<p><b>Suggestion:</b></p>

<form>

Search<input type="text" onkeyup="showMatch(this.value)">

</form>

<div id="mydiv"><b> info......</b></div>

</body>

</html>

 fetch.php

<?php

$a=array("apple","litchi","banna","anar");

$q=$_GET["q"];

if(strlen($q)>0)

{

$match="";

for($i=0;$i<count($a);$i++)

{

if(strtolower($q)==strtolower(substr($a[$i],0,strlen($q))))

{

if($match=="")

{

$match=$a[$i];

}

else

{

$match=$match.",".$a[$i];

}

}

}

}

if($match=="")

{

echo "no suggestion";

}

else

{

echo $match;

}

?>

 2) 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 in3NF for the above and solve the following. Using above database write a scriptin PHP to accept a competition name from user and display information ofstudent who has secured 1st rank in that competition.     

 

Slip30.html

 

<html>

 <body>

 <form action="slip30.php" method="get">

 Enter the name of competition  :  <input type=text name=comname><br>

<input type=submit value=SUBMIT>

 </form>

 </body>

 <html>

 

Slip30.php

 

<?php

 $database="archana2"; //database name

 $c_name=$_GET['comname'];

 $con=mysqli_connect("localhost","root" ,"");//for wamp 3rd feild is balnk

 if(!$con)

 {

 die('Could not connect: ' . mysqli_error());

 }

 mysqli_select_db($con,$database);

$result=mysqli_query($con,"select * from stud,compe,scc where stud.stud_id=scc.stud_id and scc.c_no=compe.c_no  and c_name='$c_name' and rank=1")or die(@mysqli_error());

 echo"<table border='1'>";

 echo"<tr><th>sid</th><th>name</th><th>class</th></tr>";

 while($row=mysqli_fetch_array($result))

 {

 echo"<tr><td>";

echo $row['stud_id'];

 echo"</td><td>";

 echo $row['name'];

 echo"</td><td>";

 echo $row['class'];

 echo"</td></tr>";

 }

 echo"</table>";

 mysqli_close($con);

 ?>