Jump to content


Photo

Keyword Search


  • Please log in to reply
4 replies to this topic

#1 benwhitmore

benwhitmore
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 10 May 2006 - 12:49 PM

Hi Peeps,

I have one table with three fields, id, name, description.

I want to perform a keyword search on the table in the description field and then return the id of each record that has a keyword match.

I dont think this will work:-


"SELECT id FROM table WHERE description LIKE '$keyword'" 

Any ideas to point me in the right direction?

ps. I dont need to know how to display the results, its just the initial search i am stuck with

Thanks in advance!

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 10 May 2006 - 02:14 PM

That will work... have you tried it?

Info: PHP Manual


#3 benwhitmore

benwhitmore
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 10 May 2006 - 02:23 PM

oh yeah, it does!
doh, told you.... damn pollen :P

had to use wildcard in search %$keyword%, but it works!

Any idea how to search both name and description at the same time?

Thanks in advance

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 10 May 2006 - 02:28 PM

You'll have to setup an if statement that verifies that something is in both, because you'll only want to put the ones with values in them in the WHERE clause.

pseudo-code:

if something in namebox and descriptionbox
$query .= WHERE name LIKE namebox OR description LIKE descriptionbox
elseif something in namebox and nothing in descriptionbox
$query .= WHERE name LIKE namebox
etc.

You may want to give them the option to search with an OR or an AND if they specify both.

Info: PHP Manual


#5 benwhitmore

benwhitmore
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 10 May 2006 - 04:10 PM

top man, i'll check it out.

thanks again!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users