DB read: Filter settings - Where

How to use the IN operator with an array in ChronoForms DB read filter settings.

Overview

The issue occurs when using incorrect syntax to pass an array of values to the IN operator, causing SQL errors.
Use the exact syntax model.field/in:{value:["one", "two", "three"]} with double quotes and a trailing space after each comma. Alternatively, pass an array from PHP or form data.

Answered
ChronoForms v6
Ni NickOg 11 Dec, 2018
Really struggling witth uisn g IN:\ in where conditions. I hav tried all I can think of
What is the correct syntax?
mdlMembers.cb_memberstatus/IN: '"Active","Life","Honorary"'
or
mdlMembers.cb_memberstatus/IN: "'Active','Life','Honorary'"
I have tried all of the variants I can think of including setting the string in {data:memberSelector}

Stuck!
he healyhatman 12 Dec, 2018
model.field/in: ["one", "two", "three"]

What you've done is just asked it to look in a string.
Ni NickOg 12 Dec, 2018
Thanks - makes sense but
mdlMembers.cb_memberstatus/in: ["one", "two", "three"]
leads to
1064 - You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the 
right syntax to use near '' [\"one\", \"two\", \"three\"]'' at line 1
I tried escaping the " (\") and changed to ' but same effect.
he healyhatman 12 Dec, 2018
Sorry needs to be an array. So you could use a custom code block before it with
["one", "two", "three"]
And then using
model.field/in:{var.jsonde:custom_code_name}
Passing it an array from PHP will work too without needing it to be jsondecoded first, or an array from your form data so field/in:{data:selected} if you had for example a checkboxes group called 'selected'.
Ni NickOg 12 Dec, 2018
Will try again tomorrow. I really must learn json but I think I understand the PHP approach.
Thanks again
he healyhatman 12 Dec, 2018
UPDATE: You can create an array with a shortcode (if you really need to) and get it done like this

model.field/in:{value:["one", "two", "three"]}
Ni NickOg 12 Dec, 2018
Answer
Morning

That latter fixed it but worth noting that the syntax is EXACTLY as you proposed. It fails if you use ' rather than " or omit the trailing space after each comma.

Many thanks.
Nick
This topic is locked and no more replies can be posted.