Jump to content

Archived

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

benwhitmore

Keyword Search

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!

Share this post


Link to post
Share on other sites
That will work... have you tried it?

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.