benwhitmore Posted May 10, 2006 Share Posted May 10, 2006 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 withThanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/9469-keyword-search/ Share on other sites More sharing options...
ober Posted May 10, 2006 Share Posted May 10, 2006 That will work... have you tried it? Quote Link to comment https://forums.phpfreaks.com/topic/9469-keyword-search/#findComment-34916 Share on other sites More sharing options...
benwhitmore Posted May 10, 2006 Author Share Posted May 10, 2006 oh yeah, it does!doh, told you.... damn pollen :Phad 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 Quote Link to comment https://forums.phpfreaks.com/topic/9469-keyword-search/#findComment-34920 Share on other sites More sharing options...
ober Posted May 10, 2006 Share Posted May 10, 2006 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 descriptionboxelseif something in namebox and nothing in descriptionbox $query .= WHERE name LIKE nameboxetc.You may want to give them the option to search with an OR or an AND if they specify both. Quote Link to comment https://forums.phpfreaks.com/topic/9469-keyword-search/#findComment-34922 Share on other sites More sharing options...
benwhitmore Posted May 10, 2006 Author Share Posted May 10, 2006 top man, i'll check it out.thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/9469-keyword-search/#findComment-34954 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.