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)"; Link to comment https://forums.phpfreaks.com/topic/110618-solved-make-these-if-statements-scaleable/ 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)"; ?> Link to comment https://forums.phpfreaks.com/topic/110618-solved-make-these-if-statements-scaleable/#findComment-567513 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)"; Link to comment https://forums.phpfreaks.com/topic/110618-solved-make-these-if-statements-scaleable/#findComment-567517 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 Link to comment https://forums.phpfreaks.com/topic/110618-solved-make-these-if-statements-scaleable/#findComment-567526 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... Link to comment https://forums.phpfreaks.com/topic/110618-solved-make-these-if-statements-scaleable/#findComment-567535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.