$searchtextterms = $in{'searchtextterms'}; $origterms = $searchtextterms; $escterms = $searchtextterms; $escterms =~ s/ /%20/g; $searchtextterms =~ s/\'/\\'/g; $andor = $in{'andor'}; $andor = "AND" if ($andor eq ""); # break searchtextterms on white space to do AND or OR strings @words = split (/ /, $searchtextterms); $num_words = @words; $terms_string = "(title Like '%$words[0]%' OR description Like '%$words[0]%' OR organization Like '%$words[0]%' OR type Like '%$words[0]%')"; for ($n=1; $n<=$num_words-1; $n++) { $terms_string = $terms_string . " $andor (title Like '%$words[0]%' OR description Like '%$words[0]%' OR organization Like '%$words[0]%' OR type Like '%$words%')" if ($words[$n] ne ""); } $SQL = "SELECT num FROM database WHERE ($terms_string)";