Script for adding search facility in a site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vivekjain
Forum Commoner
Posts: 76
Joined: Thu Jan 08, 2004 12:38 am

Script for adding search facility in a site

Post by vivekjain »

Hi,
I would like to know how to add a search facility in a website using PHP. If you know of any resources kindly let me know. Thanks
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You would usually have most of the data on the site - i.e. forum posts, news items, articals, tutorials etc - stored in a database and then you simply search it for the keyword the user entered:

SELECT * FROM table WHERE data_text LIKE '%$search_phrase%';

If you dont store the site data in a database then things are a bit more complicated, but work on the same process - you just have to search the individual pages on your site.

To speed things up you could put keywords for each page of your site into a search file, then php can search this file to get quick results.
Post Reply