Alright, this is somewhat of an AJAX search that I am using for my site.
The Search Form
<html>
<head>
<script src="selectuser.js"></script>
</head>
<body>
<form>
Select a User:
<input name="users" onkeyup="showUser(this.value)" value="Search">
</form>
<p>
<div id="txtHint"><b>User info will be listed here.</b></div>
</p>
</body>
</html>
and the JavaScript
var xmlHttp
function showUser(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getuser.php"
url=url+"?q="+str
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 getuser.php
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'NeXEA);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("tylerper_wordpress", $con) or die(mysql_error());
$sql="SELECT * FROM perroux_posts WHERE post_content LIKE '%".$q."%' OR post_title LIKE '%".$q."%' AND post_type != 'page'";
$result = mysql_query($sql, $con) or die(mysql_error());
echo $sql;
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Article</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['post_title'] . "</td>";
echo "<td>" . $row['post_content'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
What I am wondering is how could I fix the output to be like how it would be in a google search. Showing 10-15 words between the instances of the word(s) and/or bolding the word where it exists in the excerpt.
Any help is much appreciated
-NeXEA