tontox5 Posted June 17, 2008 Share Posted June 17, 2008 This is part of a mysql query, and I just can't figure out how to make it scaleable. Anyone got ideas? if ($word_count==1) $boolean_query = "('+$search_words[0]*' IN BOOLEAN MODE)"; if ($word_count==2) $boolean_query = "('+$search_words[0]* +$search_words[1]*' IN BOOLEAN MODE)"; if ($word_count==3) $boolean_query = "('+$search_words[0]* +$search_words[1]* +$search_words[2]*' IN BOOLEAN MODE)"; if ($word_count==4) $boolean_query = "('+$search_words[0]* +$search_words[1]* +$search_words[2]* +$search_words[3]*' IN BOOLEAN MODE)"; if ($word_count==5) $boolean_query = "('+$search_words[0]* +$search_words[1]* +$search_words[2]* +$search_words[3]* +$search_words[4]*' IN BOOLEAN MODE)"; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 how about: <?php $boolean_query = "('"; for($n=0;$n < $word_count;$n++){ $boolean_query .= '+'.$search_words[$n].'* '; } $boolean_query .= "' IN BOOLEAN MODE)"; ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 is $search_words just a numeric array and $word_count the number of items in that array? if so you can also use: $boolean_query = "('+".impload("* +",$search_words)."*' IN BOOLEAN MODE)"; Quote Link to comment Share on other sites More sharing options...
tontox5 Posted June 17, 2008 Author Share Posted June 17, 2008 Hey Rhodesa, the first code you gave me works great. I didn't know you could append to the $boolean_query variable by adding a period before the equal sign. Learn something new every day, A grateful beginner, Nick Quote Link to comment Share on other sites More sharing options...
rhodesa Posted June 17, 2008 Share Posted June 17, 2008 the second code should have been: $boolean_query = "('+".implode("* +",$search_words)."*' IN BOOLEAN MODE)"; ...i just can't spell... Quote Link to comment 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.