Jump to content

Keyword Search


benwhitmore

Recommended Posts

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

[code]

"SELECT id FROM table WHERE description LIKE '$keyword'"
[/code]

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!
Link to comment
https://forums.phpfreaks.com/topic/9469-keyword-search/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/9469-keyword-search/#findComment-34922
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.