You may remember me from such plug-ins as http://community.iwebkit.net/viewtopic.php?f=16&t=339 and now, i am back!
There has been one or two topics based on searches around the forum.. and how to use one, and specifically an aax search, so i built one! I have a demo, and screens.
Screens

P.S. The search button is purely cosmetic
You can take a look at my demo here: http://tarnfeldweb.com/dev-kit/ajax-search.html and tell me anything i could improve
Oh and by the way... it searches as you type: I currently have the following search terms in my database
- Google
- Bing
- Yahoo
- Ask
Download
http://tarnfeldweb.info/dev-kit/ajax%20search.zip
Please read the README.TXT file
How to modify the php search for your database:
Quite a few people has asked, how can i modify this for my already implemented database? Well here is a hopefully useful short tutorial.
My database, has the following fields:
id (auto increment)
name
url
And you can see with this php (commented) how these fields are taken into consideration:
- Code: Select all
$sql = "SELECT * FROM `pages`
WHERE `name`
LIKE \"%"
.$_POST['query'].
"%\" ORDER BY id ASC;";
(Don't separate this out onto lines in your actual code!)
Lines commented:
1) Declaring the mysql query statement and SELECTING *(all) FROM the table `pages`
2) Where the field `name`
3) .. is LIKE
4) %(wildcard) POSTED QUERY %(wildcard)
5) Order rows by their ID in the database, ASCending
The use of wildcard, allows anything before or after the query, this is the real 'search' part.
Now we return all the rows in the database (search results) in a nice friendly format, that the good old jquery POST asked for
- Code: Select all
if(mysql_num_rows($result)==0){
echo("<li class=\"textbox\"><p>No search results matched your query</p></li>");
}
else {
while($row = mysql_fetch_array($result)) {
echo("<li class=\"menu\">");
echo("<a href=\"".$row['url']."\">");
echo("<span class=\"name\">".$row['name']."</span>");
echo("<span class=\"arrow\"></span>");
echo("</a>");
echo("</li>");
}
}
Lines commented again:
1,2) If the number of rows returned is 0, echo on the page that no results were returned
3) Else do the following:
4) For each item in the arrayed rows, returned by the search SQL statement, do the following:
5) Make a new <li class="menu">
6) Make an <a> which links to the url that is stored in the database for that row
7) Echo out the 'name' field stored in the database for that row into an <span>
8) Shove in an arrow
9,10,11) Close it all off
I hope this is any use to you? I dont really want to explain it even more.. but here is a tip for searching in more than one field in your database:
- Code: Select all
$sql = "SELECT * FROM `pages`
WHERE `name`
LIKE \"%"
.$_POST['query'].
"%\"
OR
`othername`
LIKE \"%"
.$_POST['query'].
"%\"
ORDER BY id ASC;";
Simply use the "OR" operator in your mysql statement




