Choose a query by a select value

Hi guys,
I’ve a question.
I’ve a page with a foto gallery inside it.
I want to apply different queries according to the value of a select.
I mean, there is a select with 2 option:

  • shows all pictures

  • shows only the picturs with relations with city (it’s just an example)

So there must be two different server actions each one with its own query or one server action
with a conditionl tree:
(if the select value is then query 1, else query 2).
I want the page runs the right query according to the value of the select.

This is the link to the page:
https://www.campaniaturismo.org/test_room/test_select_and_queries.php

Has someone an idea?
Thank you guys

You can use ‘Contains’ (as a condition in the Server Connect query that populates your Select) and in the pages Select have no value but text (Show All) for the first option in your select and populate the select list with your query for the remaining photos using their id’s as the value (maybe a uid or whatever you use) and the photo title as the text. This way on initial view all the images will be shown, and then upon selection only the selected will display.

Don’t forget when you add the Action to your page to specify the Select List as the filter!

Thank you Dave but this is not the case, I guess.
The problem is not how to filter a query.
When you filter a query you restict the result by a value but the query is alway the same.
My case is different.
I have two or more different queries because I want to show all the picture (simple query without join between tables) or, for example, only the picturs without relations with cities (this is a left join between two tables).
So I have two queries depending of the value of the select

Let me be clearer.
Look at this page:
https://www.campaniaturismo.org/admin/admin-foto-list.php
The page as three tabs. Each tab has is own query.
I wanto to take the tabs off and to replace them with a select.
Here are the two queries:
without join
simple query without join
with join
query with join
At least, here is a template of the page I’d like to do instead of the previous one
https://www.campaniaturismo.org/test_room/test_select_and_queries.php
(PS: it would be better without button)

Here is something I did that sounds similar to your situation.

I have a users table in an admin section of my web app. It can be filtered by using 2 selects.
One for the finding users by organisation the other for finding users by role/permission.

In my query. I used my user db table as the base of the query, using select distinct values(otherwise users would appear more than once in the list if they where in multiple organisations or roles).
I then inner joined two join tables (users x organisations & users x roles).

The select values where sent as get variables, and I filtered my query using the following.

It’s not outlined in the screen shot, but if both selects are empty the full list of users will be returned. Also my selects have 1 default static value which is empty hence the “”.

Hi Tesla,
thank you very much for your attention.
I’ve some problems to understand your post.

  1. Do you have just 1 query? If I undestand you have joins with 2 different table and you want to activate the right join according to the velues of the selects. Is it possible to do this with just 1 query?
  2. on the page, do you put the select inside a form? if yes do you set the form method on “get”? This you you must degine a get variable in server action and, maybe in app too. Is it right?
    I guess you have understand me but It’s not so easy go to the traget.
    So I hope you can help me even further.
    Have a nice day

Is the html structure displayed on the page the same for your 3 different query results?
If it is not - how do you expect to just change the query? You should also load the new HTML structure if they show different things …

Hi Teodor,
the html structure is exacly the same.
A row, a clumn and a table.
The table has a row with a repeater.

Well then just use 3 conditions in server connenct with 3 database query steps with the same names.

Add a GET variable and use it in your conditions. Then bind the values of the select to this GET variable in the server connect component on the page.

This way your repeat created by my_query will be the same in the 3 cases and only the data will reload.

Thank you very much.
With data view too

https://www.campaniaturismo.org/test_room/test_select_and_queries_and_dataview.php

If you think it’s usefull I can make a spet by step document for wappler documentation.
Let me know

Thank you Tesla.
I’ll try you solution as soon as possible.

Hi Teodor,
There’s still a problem.
Check the page:
https://www.campaniaturismo.org/admin/admin-foto-list.php
Pass the mouse over the images.
If you check the link for each page you can see the idfoto passed at the end of the link itself.
It’s right but it happends only if it’s selected the first option in the select “MOSTRA TUTTE LE FOTO”.
Here is my set up in details.


Can you help me.
Nice day

Well check your queries then, they return null values:

Thank you Teodor.
It looks running well now.
Just another information.
Where did you take that screenshot?
I mean how did you do that check?
Thank you again and have a nice day

You can check the reply in Browser Dev tools > Newtwork > XHR
the same as shown here:

:ok_hand: :+1: :+1: