Forum Moderators: coopster
I will have a field in the database called "Keywords" and they will be separated by commas.
I know I can use:
$search_array = explode(" ",$searchwords);
to parse their submitted search terms into individual words, and
$keywords_array = explode(",",$keywords);
to break out the database field into individual words as well. I just cant think of the easiest way to compare here. Am I on the right track or have I lost my mind?
read more about this [mysql.com...]
so u'll need only
$keywords = str_replace(","," ",$keywords);
to prepare the search string
But if all you are doing is trying to make a search, to see how well you would do, then here is a couple of tips on the method you have choosen.
Since the words in the database are going to be in a field, seperated by comas (?) you could use two methods of checking them in there. (Well, two that I know about with out grabing a book), The first is using LIKE and the second is useing REGEX
[mysql.com...]
Regex is very powerful, and slightly faster than like, depending on the statment you use.
There is probably a reason for having all those words in there (what are we using here a varchar 255? field), but I can't think of a single reason I would do it that way.
There is a reason they might get like that eventually, but not one where they would start out like that.
Anyway, those are two methods which can get a word pattern out of a large text field.