grnt
asked on
Concatenate search fields
I'm building my web site using php and mysql. I'm converting an exiting website from ASP/MS ACCESS. I'm having a problem with a simple select statement that utilises two drop down select boxes and one single keyword box. The results from the drop down boxes (County and License fields) work well. The single keyword box, which searches several fileds (Company, Title, Description), produces syntax errors. This is the code I'm trying to write on the results page:
$query_rsSearch = sprintf("SELECT * FROM projects WHERE County LIKE '%%%s%%' AND License LIKE '%%%s%%' AND Company+','+Title+','+Desc ription+' LIKE '%%%s%%'", $varcounty__rsSearch,$varl icense__rs Search,$va rkeyword__ rsSearch);
Any suggestions on how to correct this world be appreciated.
$query_rsSearch = sprintf("SELECT * FROM projects WHERE County LIKE '%%%s%%' AND License LIKE '%%%s%%' AND Company+','+Title+','+Desc
Any suggestions on how to correct this world be appreciated.
ASKER
Thanks for the input. Good news, the syntax error message has gone but when I enter a keword in the keyword box, it produces no results. The County and License fields still produce results but the keyword field draws a blank. Any further suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$query_rsSearch = sprintf("SELECT * FROM projects WHERE County LIKE '%%%s%%' AND License LIKE '%%%s%%' AND Company+','+Title+','+Desc
Also, you should be careful of SQL injection and use mysql_escape_string on all data input by the user.
$query_rsSearch = sprintf("SELECT * FROM projects WHERE County LIKE '%%%s%%' AND License LIKE '%%%s%%' AND Company+','+Title+','+Desc
Good luck.