bccamp
Technical User
- Jan 20, 2005
- 69
I'm trying to write a search routine for my DB. I have a field, Title, that contains multiple pipe delimeted statements for each row of data. I have a field, KeyWord, that contains the 'key words' from Title, Description, and Header. I can search using a single query, explode the pipe delimeted statements, and extract the statement that contains the single term I'm looking for:
Now, after all that, what would be the best way to attack using multiple search terms? My KeyWord field contains more than just the data from the Title field. Using
would not work correctly. Is there a "best" place to extract and compare the results from 2, 3, or 4 search terms? Is there a way to dynamically search 2,3,or 4 terms using the $query routine? I thought about writing the Search Results from the first KeyWord to a file, then using a loop routine to extract results from that based on each keyword, but that seems a little excessive. Better Way?
Code:
$query="SELECT Title FROM company WHERE KeyWord LIKE '%$key%'";
$result=mysql_result($query);
...assign all values to a string
...loop the results
$Title2=(explode("|",$Title));
sort($Title2);
$cnt=count($Title2);
for ($a=0;$cnt>$a;$a++){
$Title3=stristr($Title2[$a],$key);
if ($Title3!=NULL){
echo "$Title2[$a]"
}
}
Code:
...WHERE KeyWord LIKE '%$key1%' AND KeyWord LIKE '%$key2%'";