Jump to content

[SOLVED] what am i missing!!!!!!!!!!


jmurch

Recommended Posts

 

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"); 

Link to comment
https://forums.phpfreaks.com/topic/156047-solved-what-am-i-missing/
Share on other sites

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!

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");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.