PhP Search


#1

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,

Ricky


#2

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


#3

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,

thanks

ricky


#4

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:


#5

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


#6

Say you have the following database setup:

PAGES:

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

PAGE_KEYWORDS:

  • 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:

create_page.php:

  • 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)

showpage.php:

  • select * from pages where pageid = $requestedPageID

search.php:

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

Or somethin like that.