Search and Advance Search

Hello,

I’m new to wappler and am in my learning phase. I’m trying to make an inventory management system and I want to make a search field which takes the column name and the keyword to search. Is there any way we can use the parameters in the database query for dynamic column_name in the WHERE clause? Is there any way to create dynamic queries?

If i am understanding correctly, you want to search multiple columns with one text input?

Idk if this is the best way.
But check multiple columns in where clause, to see if it equals or contains the search value.
and then set that to ‘or’ block instead of ‘and’

Does that help?

1 Like

Welcome to Wappler!

If I understand you correctly, the solution @Hinky supplied is correct. If not, can you provide more details?

1 Like

Hi @Hinky, Thank you so much for your help. This is something that I can definitely do. However, I have about 50 Columns in my products table so I was hoping I could get a way so that I don’t have to check multiple columns and just bind the column name with a variable/parameter.

1 Like

There’s no official support for dynamic queries, you can’t bind a parameter to a column name.

However, there’s a way to do it in a custom query, but you’d need to be really careful to avoid the possibility of SQL Injection (e.g.: remove all characters that don’t match the a-z charset):

If you can, stick to the official methods provided by Wappler - this is definitely not meant for beginners

2 Likes

@Apple Thank you so much for the solution and the warning along with it. It worked like a charm. Hoping to learn more.

Another way I can imagine you could do this would be to create a SQL view with a field which is a massive concatenation of the fields you want to search, then query that view in a server action…

Would love to see this feature implemented, as I’m working on the same thing right now and it gets unwieldy creating all the conditions in the query builder.