PhP Search

Hi, I was wondering if anyone would be able to help me:

I would like to add a search function to my site, but i lack the knowledge or the experience to do so. Would anyone be able to help me out, even just a pointer in the right direction would be awesome!

Thanks in advance,


What exactly would you like to have searched? Items in a database, produced HTML, articles in files?

I have a site that I would like to be able to search, it uses php pages (though they are mainly html) I would like the search function to either index the pages regularly, or search on demand and look for the keywords suggested by the user,



Can’t you have the creator of the pages input keywords per-page, put those keywords in a database and have the search function skim those keywords upon request?

It’s not a very smart way of implementing a search function, but then again, I’m not a Google employee :wink:

see… that is how sad i am with php :cry: even what you mentioned makes me just stare and raise my eyebrows… Though it must be cool being a google employee

Say you have the following database setup:


  • pageid (int)
  • authorid (int)
  • content (mediumtext)


  • pageid (int)
  • keyword (varchar)

This would be a 1:M relation, and the link would be pageid (which is PK and auto_increment in table PAGES).
Your pages could look like this:


  • textarea for content
  • several input boxes for keywords
  • submit button

create_page.php on submit:

  • insert into pages values (null, $yourUserID, $content)
  • $insertID = mysql_insert_id()
  • insert into page_keywords values ($insertID, $keyword1)
  • insert into page_keywords values ($insertID, $keyword2)
  • insert into page_keywords values ($insertID, $keyword10)


  • select * from pages where pageid = $requestedPageID


  • select p.* from pages as p, page_keywords as k where k.keyword = $searchWord AND p.pageid = k.pageid

Or somethin like that.

Sponsor our Newsletter | Privacy Policy | Terms of Service