Catch-all search MySQL query building

adictomohaa

New Member
I have some code that builds SQL queries to perform a lenient, catch-all kind of search on a potentially large table that loooks a little like this\[code\]// $find_array derived from search string with space or comma used as a delimiterforeach($find_array as $term){ $clauses[]="( OR last_name SOUNDS LIKE '$term' OR first_name SOUNDS LIKE '$term' OR first_name LIKE '%$term%' OR email SOUNDS LIKE '$term' OR email LIKE '%$term%' [etc...] OR city LIKE '%$term%' OR company SOUNDS LIKE '$term' OR company LIKE '%$term%' )";}\[/code\]This may be a very wrong way of doing it, but I guess it made sense at the time. Looking at the queries this produces, though -- they are, of course, even with limits on search terms, about a mile long and littered with ORs. Is this a terrible crime of some sort -- in terms of performance or otherwise? Is it better to use the IN clause whenever possible?
 
Back
Top