jmurch Posted April 29, 2009 Share Posted April 29, 2009 I cannot figure this out. I have a single text box ($keyword) that submits up to 3 keywords to search multiple columns. I explode, populate $keyword1, 2, and 3 with either array values or wildcards and run the query. What is happening is the query always runs with $keyword1 populated but when $keyword2 or 3 has a value the query won't return any values even though running it in a query browser works. The query does run fine however when $keyword2 or 3 have static values entered in the query......... TIA $keyword_value = $keyword; $keyword_array = explode(' ',$keyword_value); if(sizeof($keyword_array) == 1) { reset($keyword_array); $keyword1 = $keyword_array[0]; $keyword2 = "%"; $keyword3 = "%"; }elseif(sizeof($keyword_array) == 2) { reset($keyword_array); $keyword1 = $keyword_array[0]; $keyword2 = $keyword_array[1]; $keyword3 = "%"; }elseif(sizeof($keyword_array) == 3) { reset($keyword_array); $keyword1 = $keyword_array[0]; $keyword2 = $keyword_array[1]; $keyword3 = $keyword_array[2]; } $get_parts_query = mysql_query("SELECT cat1, cat2, part, description, price, concat(parts_list.cat1,' ',parts_list.cat2,' ', parts_list.part,' ', parts_list.description) as 'search_text' from parts_list having ((search_text like '%$keyword1%') and (search_text like '%$keyword2%') and (search_text like '%$keyword3%')) LIMIT 400"); Quote Link to comment https://forums.phpfreaks.com/topic/156047-solved-what-am-i-missing/ Share on other sites More sharing options...
mikesta707 Posted April 29, 2009 Share Posted April 29, 2009 instead of having ((search_text like '%$keyword1%') and (search_text like '%$keyword2%') and (search_text like '%$keyword3%')) LIMIT 400"); try having ((search_text like '%$keyword1%') or (search_text like '%$keyword2%') or (search_text like '%$keyword3%')) LIMIT 400"); Or do you need the returned value to have search_text like all three keywords? hope that helps! Quote Link to comment https://forums.phpfreaks.com/topic/156047-solved-what-am-i-missing/#findComment-821489 Share on other sites More sharing options...
jmurch Posted April 29, 2009 Author Share Posted April 29, 2009 mikesta707, I need to match all three keywords which is why I have the wildcards if there is only one (or two) keyword(s). Quote Link to comment https://forums.phpfreaks.com/topic/156047-solved-what-am-i-missing/#findComment-821490 Share on other sites More sharing options...
jmurch Posted April 29, 2009 Author Share Posted April 29, 2009 Solved this but I'd still like to know why. I modified the search_text to have 3 one for each keyword and it works fine. Can anyone explain why? TIA mysql_query("SELECT cat1, cat2, part, description, price, concat(parts_list.cat1,' ',parts_list.cat2,' ', parts_list.part,' ', parts_list.description) as 'search_text', concat(parts_list.cat1,' ',parts_list.cat2,' ', parts_list.part,' ', parts_list.description) as 'search_text2', concat(parts_list.cat1,' ',parts_list.cat2,' ', parts_list.part,' ', parts_list.description) as 'search_text3' from parts_list having ((search_text like '%$keyword1%') and (search_text2 like '%$keyword2%') and (search_text3 like '%$keyword3%')) LIMIT 4000"); Quote Link to comment https://forums.phpfreaks.com/topic/156047-solved-what-am-i-missing/#findComment-821494 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.