Koren
Posts: 83
|
| Posted: 06/17/2011, 8:40 AM |
|
I need to do a simple str_replace() on a text box for a search.
I was playing with:
$Container->s_write_up->SetValue(str_replace(array("'",'"'), "%",$Container->s_write_up->GetValue()));
on the Search Box Record Form Before Update
and that didnt work.
I would rather edit the "Before Execute Select" Event on the Results Grid and have the str_replace() there. I have a few other fields in this search and only want to replace the one called "s_write_up". How can I call the s_write_up parameter and run the str_replace before we see the result.
I am pretty sure that it is right there in front of me and too burnt out to find it.
THANKS SOOO much for your help!
Koren
|
 |
 |
Koren
Posts: 83
|
| Posted: 06/17/2011, 9:33 AM |
|
OK had a cup of coffee, stopped to think about it for a minute and solution clicked...
BeforeBuildSelect:
// Below is to replace all single and double quotes with wildcards % for search
global $searchTerm;
$searchTerm = CCGetParam("s_write_up","");
if ($searchTerm != ""){
$newSearchTerm = str_replace(array("'",'"'), "%",$searchTerm);
$Component->DataSource->Where .= " AND ( the_advertiser.ad_name LIKE '%".$newSearchTerm."%' OR the_advertiser.write_up LIKE '%".$newSearchTerm."%')";
}
Just as IMPORTANT:
REMOVE any existing Where statements in the Visual Query Window for the grid and that search field. The above custom code is to replace it.
|
 |
 |
jjrjr2
Posts: 131
|
| Posted: 06/17/2011, 10:35 AM |
|
Hi
Just curious why you needed to do this..
Query builder can do a LIKE query on your database using the s_write_up paramater from the URL..
Would be interested to know your issue here...
Thanks
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com
Real Web Development At: http://RealWebDevelopment.us |
 |
 |
Koren
Posts: 83
|
| Posted: 06/17/2011, 11:05 AM |
|
Hi John,
Oh no i wasn't trying to create a LIKE query.
You see, the data that is being queried has many entries that use "punctuation" quotation marks and apostrophes. In other words those fancy curled apostrophes, not the ordinary vertical typewriter apostrophe and quotation marks found on keyboards. SO when a user was doing a search and included the a common vertical apostrophe found on the keyboard for let say, "Jimmy’s Seafood", it would yield a zero as a result. So, I decided to replace all apostrophes and quotation marks in the search parameter as a wildcard "%" to just disregard the punctuation completely.
Now I get proper results on searches.
Sometimes my logic might be murky, but I needed a quick fix and this seems to do the trick. For now anyways. :)
|
 |
 |
|