Variables in MySQL queries

Hi All,
I’m new to weweb and currently working on creating a customer facing web portal with a MySQL back end. I’ve got my database connected successfully, but some of my tables are too big and won’t fetch all data.

What I would like to do to limit the records returned is query to select all records that have the same email as the current user.
I’m having a hard time figuring out how to add variables to the query! Is this possible, or does it need to be filtered after the data is fetched?
Here’s the query I’m trying to write:

select * from deals where email = (user email variable);

I tried putting in the variable ID:
select * from deals where email = variables[‘734d23b0-d7a2-4bfb-9612-13f3432f1de2-value’];

I played around with using the formula too but couldn’t get that to work either.
Any help is appreciated!!!

Hello,

You can use the bind button at the left of the row. You will be able to use variable of the user and do what you want

When I try the query within the formula section, it doesn’t work.
What am I missing here?

The input of the dymanic query it’s not a string, it’s a javascript expression that is evaluated to generate the final value.
You need to create a string with concatenations (see the weweb formulas in the panel) or template literals (something like `select * from deals where email = ${yourVariableHere} `

Of course at this point you are trusting yourVariableHere not to do dangerous things with your query.

2 Likes

Thank you!!!
Final snippet:
return ‘select * from deals where email = "’ + variables[/* email2 */‘c8b1ba4b-350b-407f-80aa-a7e442b1e6bb’].toString() + ‘";’;