Welcome Guest, Not a member yet? Register   Sign In
Database Query Filter

Perhaps you should consider filtering those out before you reach the final query.  In more complex queries, case and union are both commonly used to construct SQL statements.  Given that, you could use str_ireplace (case insensitive) to replace target strings with other strings like an empty.   So your searchIn variable could be either strings or arrays of strings which makes things nice.  I used a double underscore as the replace value so you could see the result easier.  You most likely want to just clip the find words out with a simple empty character.

PHP Code:
$find = array('Case'

$searchInArray  = array('This is the union'
'that case was not mine'
'nor was the information_scheme ready'

$searchInString 'This is the union that case was not mine nor was the information_scheme ready';

$replaceWithString '__';

$resultA str_ireplace($find$replaceWithString$searchInArray);
$resultB str_ireplace($find$replaceWithString$searchInString);

// results will display as follows
echo "resulA:" print_r($resultAtrue);
resultA: Array ( 
0] => This is the __ 
[1] => that __ was not mine 
[2] => nor was the __ ready 

"resultB:" print_r($resultBtrue);
resultBThis is the __ that __ was not mine nor was the __ ready 

str_ireplace takes arrays or strings as arguments, but gives different results depending. If your searchIn variable is a string that works just fine. I gave both examples above.  You will need to plan how you build queries.  Dynamic queries can do amazing things, if crafted correctly.

Messages In This Thread
Database Query Filter - by smshr88 - 10-27-2015, 12:19 AM
RE: Database Query Filter - by pdthinh - 10-27-2015, 07:09 PM
RE: Database Query Filter - by Kirkja - 10-27-2015, 08:23 PM

Theme © iAndrew 2016 - Forum software by © MyBB