Test4.php:
<?php
$q=$_GET['q'];
$c=new mysqli("localhost","root","naina","nearur");
if($c->connect_error){
die("eror : ".$c->connect_error);
}else{
$sql="Select * from bank";
$result=$c->query($sql);
$h="";
if($result->num_rows>0){
while ($row=$result->fetch_assoc()) {
$n=$row['userid'];
if(stristr($q, substr($n, 0,strlen($q)))){
if($h == ""){
$h=$n;
}else{
$h.=" , ".$n;
}
}
}
echo $h;
}
}
?>
Test4.html:
<html>
<head>
<title></title>
<script type="text/javascript">
function show(){
alert("hello");
}
</script>
<script>
function showHint(str) {
if(str.length==0){
document.getElementById("h").innerHTML="";
}else{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("h").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "test4.php?q=" + str, true);
xmlhttp.send();
/*var xml=new XMLHttpRequest();
xml.onreadystatechange=function(){
if(this.readyState==4 && this.status==200){
alert("hello");
document.getElementById.("h").innerHTML=this.responseText;
}
};
xml.open("POST","test4.php",true);
xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xml.send("q="+str);*/
}
}
</script>
</head>
<body>
<form>
<input type="text" onkeyup="showHint(this.value)">
</form>
<p id="h">Suggestions</p>
</body>
</html>
<?php
$q=$_GET['q'];
$c=new mysqli("localhost","root","naina","nearur");
if($c->connect_error){
die("eror : ".$c->connect_error);
}else{
$sql="Select * from bank";
$result=$c->query($sql);
$h="";
if($result->num_rows>0){
while ($row=$result->fetch_assoc()) {
$n=$row['userid'];
if(stristr($q, substr($n, 0,strlen($q)))){
if($h == ""){
$h=$n;
}else{
$h.=" , ".$n;
}
}
}
echo $h;
}
}
?>
Test4.html:
<html>
<head>
<title></title>
<script type="text/javascript">
function show(){
alert("hello");
}
</script>
<script>
function showHint(str) {
if(str.length==0){
document.getElementById("h").innerHTML="";
}else{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("h").innerHTML = this.responseText;
}
};
xmlhttp.open("GET", "test4.php?q=" + str, true);
xmlhttp.send();
/*var xml=new XMLHttpRequest();
xml.onreadystatechange=function(){
if(this.readyState==4 && this.status==200){
alert("hello");
document.getElementById.("h").innerHTML=this.responseText;
}
};
xml.open("POST","test4.php",true);
xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xml.send("q="+str);*/
}
}
</script>
</head>
<body>
<form>
<input type="text" onkeyup="showHint(this.value)">
</form>
<p id="h">Suggestions</p>
</body>
</html>