Hi,
I'm trying to put together a PHP Ajax search against an mySQL database yet doesnt seem to work .. HELP!
I had to resort to using frameset which I dont really want to do.
what I'm trying to is perform a search against a mysql database and display the results on the same page. Want the ability to perform multiple search without a refresh or change of page.
so far this is what i have
Index.html
<html>
<head>
<script src="selectuser.js"></script>
</head>
<body>
<div align="center"
<form name="form" action="search.php" method="get">
<input type="text" name="q" />
<input type="submit" name="Submit" value="Search" />
<div align="right">
<select name="list">
<option value="10"> 10 </option>
<option value="20"> 20 </option>
<option value="50"> 50 </option>
</select>
</div>
</form>
</div>
<div id="txtHint"><b>User info will be listed here.</b></div>
</body>
</html>
var xmlHttpfunction showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="search.php"
url=url+"?q="+str+"?list="
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
The code calls a search.php which performs the search against the database and creates the tables.
Search.php echos the tables using DIV .
Any ideas on how to improve this ?