brad
June 16, 2023, 6:46pm
1
I have a recordset that filters on select form field value. It works great.
But what I would like to do is to show all records by default. Right now the recordset is empty and I would like to show all records if no option is selected from the select field. So if nothing is selected in the Select Office field it should show all records.
Teodor
June 16, 2023, 6:58pm
2
Set your first select option value to value=""
and use the condition option in the query builder to check if your $_GET.select_input
As a @Teodor says you want to have a condition in the query we actually solved this before quite a while ago so i will drop that thread here for reference:
In my situation when I wanted ‘all’ results I did this
[Screenshot 2021-12-02 at 01.51.48]
What I did was the all option was static for me so I added a value to the select with a value of ‘published’
Then when it comes to the query I have the IN function wrapped in a condition that only activates when the selects value is not ‘published’
If you need certain filters for when its on all ‘published’ in my example you could wrap this is a condition below but this time when the value is == ‘publ…
brad
June 16, 2023, 7:07pm
4
Seems to be more than one way to do this. All I did have my first select option as value="" and then set the query to contains instead of equal.
Teodor
June 16, 2023, 7:10pm
5
Just put the condition in a new group and use the condition for it
1 Like
Contains will work in some areas depending on the query for example
What if you had some offices called:
ace
landing space
Using ace as a filter here would return records for both offices, so it may work in certain areas but the conditions are better to prevent issues like this
Personally I would use the group with a condition
1 Like
brad
June 16, 2023, 7:14pm
7
Ah, good point. I will try and figure out how to use conditions.
brad
June 16, 2023, 8:28pm
8
Do you have an example of a screenshot of what that should look like? I’m really struggling to figure out this conditions thing.
This is what I have but it doesn’t work … still returns zero results unless office has a value.
Never tried this with a empty string I had a word value like published or all for example but maybe you could try:
{{$_GET.office != ""}}
or {{$_GET.office != null}}
My method was in the select setting the first value to say all
then the condition was {{$_GET.office != 'all'}}
It may make no difference but just a test if the empty string is the issue
brad
June 16, 2023, 9:30pm
10
I don’t think the condition is being added to the SQL at all.
WHERE p_instances.inst_programid = 22 AND
p_instances.inst_status = :P1 /* {{$_GET.status}} */ AND
c_clients.client_office = :P2 /* {{$_GET.office}} */
Teodor
June 17, 2023, 5:11am
11
Brad, it has always worked like that:
You need to use the condition in the query builder.
[Screenshot 2022-07-15 at 9.50.27]
So click this icon and select your $_GET.ev variable there. This means the filter will be applied only when the $_GET.ev returns a value, otherwise it will not be applied.
brad
June 17, 2023, 4:46pm
12
This works … on the live site. But it does’t work when you run the query in the query manager.
Thanks @Teodor ! I learned something new.