13. Write a PHP script using AJAX concept, to develop user-friendly and interactive search engine
HTML File
<html>
<head>
<title>Slip13.html</title>
<script>
function search()
{
srch=document.getElementById('txtsrch').value;
ob=new
XMLHttpRequest();
ob.onreadystatechange=function()
{
if(ob.readyState==4
&& ob.status==200)
{
document.getElementById('o').innerHTML=ob.responseText;
}
}
ob.open("GET","slip13.php?s="+srch);
ob.send();
}
</script>
</head>
<body>
<table align=center
border=0>
<tr><td><input
type=text id=txtsrch placeholder="enter search string"><input
type=button value="SEARCH" onclick="search()">
</table>
<span id=o></span>
</body>
</html>
PHP File
<?php
$search=$_GET['s'];
$con=mysql_connect("localhost","root","rsb");
mysql_select_db("slip13db",$con);
$r=mysql_query("select * from
slip13 where des='$search'");
echo "<table
align=center">
while($row=mysql_fetch_array($r))
{
echo
"<tr><td>".$row[0]."</td></tr>";
}
echo "</table>";
?>
No comments:
Post a Comment
Note: only a member of this blog may post a comment.