Thursday, 12 January 2012

Tagged under: , , , , , ,

Live Search / AutoComplete Using XML & PHP

Many a times, we need to build a search engine for our website, which can serve various purposes like searching through your site! In such cases, live search option is the most sought after, for the ease of searching!!
The code for live search can be broken down in three parts viz:
  1. HTML file
  2. PHP file
  3. XML file

Stage 1:(HTML file)

Create an html file and paste the following code in it:

Stage 2:(PHP file)

Create a php file 'livesearch.php' and paste the following code in it:

Stage 3:(XML file)

Here you have two options:
  1. Export the data from the database like MySQL in XML form.
  2. Create an XML file yourself.
However, the 1st alternative turns out to be a good one, as you don't have to write the complex XML code...the job is done by MySQL!!
In our example, the exported XML code looks like this (links.xml):

If you want to write the xml code by yourself, then I have uploaded the modified PHP & XML files in the download box present alongside.

Or, you can download it from the link

Now, load the html file in browser in localhost, & see the magic happen!!!

Look out for my next post on "Live search using PHP only" (It is better for a huge database, and is relatively smaller than the one we have written here!!)

You can for further assistance.

Kindly Bookmark and Share it:


  1. how can I customize the way the results are displayed?