Page 1 of 1

which keywords found from search

Posted: Sun May 08, 2005 11:58 pm
by hongco
not sure how to put it, but let say that I enter a phrase of 4 key words (eg: apple orange banana pine)to search on a column 'text' of a table:

Code: Select all

$query = &quote;SELECT * FROM books WHERE text ='apple' OR text='orange' OR text='banana' OR text='pine'&quote;;
let say the result yields 10 rows in which any row can have text contain either one of the fruits, a few, or all. My question is, how do we return which row contains which keyword when the result is returned? In most searching function, we return the "text" with the keyword highlighted. I want to do the opposite, I need to display the 4 keywords, and underline anyone of them which "text" contains.

If we search 1 key word at a time, that can do, but in this case, i have have than 1 phrase to begin with; thus search 1 keyword at a time sounds not a good idea, but not sure if there is any better alternative.

Thanks.

Posted: Mon May 09, 2005 9:45 am
by anjanesh
This will be impossible with a single MySQL statement alone.
You'll need to perform another check (PHP alone) from the query-result to figure out which rows contain which keywords - 2 dimensional array.
Have you tried using LIKE in MySQL ?

Posted: Tue May 10, 2005 3:34 am
by hongco
thanks for your reply. I thought about it and decided not to go this way. It takes too many queries for this part.

cheers!