HI All,
Program 1 - ajaxmain.php
----------------------
<html>
<head>
<script>
function loadDoc() {
//alert('HUP');
var
key=document.frmsearch.sname.value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange =
function() {
if (xhttp.readyState == 4 &&
xhttp.status == 200) {
document.getElementById
("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "searchstud.php?
key="+key, true);
xhttp.send();
}
</script>
</head>
<body >
<form name=frmsearch method=post>
<center>Name <input type=text name=sname
onkeyup="loadDoc()"><input type=button
value='Search Student'onclick="loadDoc
()">
</center>
</form>
<div id="demo" align=center><h2>Search
Result</h2></div>
</body>
</html>
-----------------------
Program 2 - searchstud.php
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("m301db",$con);
$sname=$_GET['key'];
$sql="Select * from tbl_student where st_name like '%$sname%'";
$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row[0];
$rollno=$row[1];
$marks=$row[2];
echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";
}
mysql_close($con);
?>
Program 1 - ajaxmain.php
----------------------
<html>
<head>
<script>
function loadDoc() {
//alert('HUP');
var
key=document.frmsearch.sname.value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange =
function() {
if (xhttp.readyState == 4 &&
xhttp.status == 200) {
document.getElementById
("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "searchstud.php?
key="+key, true);
xhttp.send();
}
</script>
</head>
<body >
<form name=frmsearch method=post>
<center>Name <input type=text name=sname
onkeyup="loadDoc()"><input type=button
value='Search Student'onclick="loadDoc
()">
</center>
</form>
<div id="demo" align=center><h2>Search
Result</h2></div>
</body>
</html>
-----------------------
Program 2 - searchstud.php
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("m301db",$con);
$sname=$_GET['key'];
$sql="Select * from tbl_student where st_name like '%$sname%'";
$data=mysql_query($sql,$con);
echo "<table border=1 align=center width=50%>";
echo "<tr><th>Name</th><th>Roll No</th><th>Marks</th></tr>";
while($row=mysql_fetch_array($data))
{
$name=$row[0];
$rollno=$row[1];
$marks=$row[2];
echo "<tr><td>$name</td><td>$rollno</td><td>$marks</td></tr>";
}
mysql_close($con);
?>
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
DeleteThis comment has been removed by the author.
ReplyDelete