saseow
Posts: 744
|
| Posted: 02/06/2009, 9:54 AM |
|
I have a text search field that will always contain one word. Is it possible to have the user enter some characters, then depending on whether they select 'begins', 'contains' or 'ends' via radio buttons, to return all words with the user entered text either at the beginning, or anywhere (contains) or at the end?
This may involve regular expressions which I know zip about.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 10:05 AM |
|
I want to clarify this. I can see the regular expressions in the query builder and I presume that
begins with (like '---%') would include all characters entered and find the words that start with these characters. Is this correct and does it matter how many characters are entered?
The main point is how I specify the parameters depending on which radio button is selected.
Thanks.
|
 |
 |
jjrjr1
Posts: 942
|
| Posted: 02/06/2009, 10:22 AM |
|
Hi.
First 2 questions answers Yes.. No...
Last question is you might have to modify the SQL in the before select event.
Check your radio button then swap in the proper SQL.
Or if you are just using the radio button value as a seach string, write a routine that can be plugged into the query builder.
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 10:41 AM |
|
Hi jjrjr1,
So, the second question which you said 'No' means that (like '---%') would only compare the first 3 characters. Is this correct or did you mean that the user could enter any number of characters and it would compare all of them?
The before select event is the one for the grid I presume and not the search form. Is there any example of how to change the SQL in this event? The SQL can be quite big depending on what the user has chosen to search by. Also, an example of checking the radio button.
I must sound pretty dim at this stage and that would be correct. Had about 2 hours sleep last night. Sorry!
|
 |
 |
datadoit
|
| Posted: 02/06/2009, 10:49 AM |
|
Remove any parameter checks for your field in the Visual Query Builder,
then:
BeforeBuildSelect:
if ($Container->ds->Where <> "") {
$Container->ds->Where .= " AND ";
}
//Begins
if ($Container->YourRadioControl->GetValue() == 1) {
$Container->ds->Where .= "your_table.YourField LIKE '" .
$Container->SearchField->GetValue() . "%'";
}
//Contains
if ($Container->YourRadioControl->GetValue() == 2) {
$Container->ds->Where .= "your_table.YourField LIKE '%" .
$Container->SearchField->GetValue() . "%'";
}
//Ends
if ($Container->YourRadioControl->GetValue() == 3) {
$Container->ds->Where .= "your_table.YourField LIKE '%" .
$Container->SearchField->GetValue() . "'";
}
|
|
|
 |
jjrjr1
Posts: 942
|
| Posted: 02/06/2009, 11:00 AM |
|
Nice datadoit.
I need to remember this.
Thanks
Having Fun?
_________________
John Real - More CodeCharge Studio Support at - http://CCSElite.com |
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 11:00 AM |
|
let me try this now. I will get back to you either with a smile or in tears.
Thanks so much.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 11:48 AM |
|
This sounds so good but I cannot get it to work. It must be something simple.
If I put the code into the beforebuildselect of the search for I get this warning "Event BeforeBuildSelect cannot have actions because datasource would not be generated."
If I put it in the same event on the grid form, I get the " Call to a member function GetValue() on a non-object in C:\php webs\domain_sales\public_events.php on line 69" error. This is my code:
if ($Container->ds->Where <> "") {
$Container->ds->Where .= " AND ";
}
//Begins
if ($Container->Radio1->GetValue() == 1) {
$Container->ds->Where .= "ds_domains.YourField LIKE '" .
$Container->SearchField->GetValue() . "%'";
}
//Contains
if ($Container->Radio1->GetValue() == 2) {
$Container->ds->Where .= "ds_domains.YourField LIKE '%" .
$Container->SearchField->GetValue() . "%'";
}
//Ends
if ($Container->Radio1->GetValue() == 3) {
$Container->ds->Where .= "ds_domains.YourField LIKE '%" .
$Container->SearchField->GetValue() . "'";
}
What am I doing wrong!
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 11:54 AM |
|
Perhaps I don't follow what is meant by "Remove any parameter checks for your field in the Visual Query Builder" I removed the entire field from the where clause. Is this correct?
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 12:34 PM |
|
I am using a radio button from the HTML page of the toolbox. Is this a problem?
|
 |
 |
datadoit
|
| Posted: 02/06/2009, 12:59 PM |
|
It goes into the grid's BeforeBuildSelect.
In your case the radio button isn't part of any datasource but comes
from a search form, so to get it's value, use
CCGetParam("YourRadioControl","").
Same for the search text field (ie: CCGetParam("searchfield","")).
|
|
|
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 1:02 PM |
|
The problem, I am sure is that I cannot reference the radio button in this line:
($container->Radio1->GetValue() == 1) gives the error:
Call to a member function GetValue() on a non-object in .
The code is going into the BeforeBuildSelect event of the grid and the Radio buttons are in the search form. Is this the problem do you think?
Please....
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 1:12 PM |
|
datadoit, I am sorry to be such a pain. Let me give this a try now.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 1:40 PM |
|
OK, no errors now but I am sure there is an error none of the 'if' statements catches even though I have one of them ticked. This is the code:
if ($container->ds->Where <> "") {
$container->ds->Where .= " AND ";
}
//Begins
if (CCGetParam("Radio1","") == 1) {
$container->ds->Where .= "ds_domains.domain LIKE '" .
CCGetParam("domain","") . "%'";
}
//Contains
if (CCGetParam("Radio1","") == 2) {
$container->ds->Where .= "ds_domains.domain LIKE '%" .
CCGetParam("domain","") . "%'";
}
//Ends
if (CCGetParam("Radio1","") == 3) {
$container->ds->Where .= "ds_domains.domain LIKE '%" .
CCGetParam("domain","") . "'";
}
Any ideas would be such a help. The URL search string shows the text selected in the text box called 'domain' but I think it is just the If statement that is messed.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 1:46 PM |
|
The URL always shows the Radio as on. Is this correct?:
This is a search for part of google
?Radio1=on&domain=goog&s_extension_id=&s_sold etc. etc.
|
 |
 |
damian
Posts: 838
|
| Posted: 02/06/2009, 1:58 PM |
|
guys isnt $Container case sensitive?
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 2:05 PM |
|
I think it is but I have changed that and still don't get any of the IF statements catching.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 2:11 PM |
|
If I echo CCGetParam("Radio1",""); I simply get 'on' even if none are clicked. I really am at a loss about this.
|
 |
 |
saseow
Posts: 744
|
| Posted: 02/06/2009, 2:20 PM |
|
I am going to sleep after this. I forgot to enter the various values for each radio button.
Thank you all for your help. What a nightmare!!!
datadoit, an excellent solution.
|
 |
 |