custom where clause

Filter database results using multiple values from a single field.

Overview

The issue occurs when a comma-separated list of values in a form field is incorrectly interpreted as a single string in a CF Read Data action's WHERE clause, causing only one record to match.
Use a custom PHP action to manually construct the SQL WHERE clause, replacing the Read Data action. This allows you to properly format the condition, such as using an IN statement or multiple OR clauses, to match all individual values from the list.

Answered
ChronoForms v7

i have a filed with some values. I dont know before arriving in the page how many values are stored in.

The filed format is 

[hid_p2] => 2,3

in my read data action, i put a php where clause like this 

(nim_piece) in {var:hid_p2} , but i have only the last record in the read data debug.

because the {var:hid_p2} change of colour, i interpret this field in the where clause as a multi field value. the values  which works are {var:hid_p2} {var:hid_p3}...

my debug show this where clause :

 WHERE ( `Carac_d`.`id_devis` LIKE '721' ) AND ( `Carac_d`.`num_piece` LIKE '2,3' );

The output that i want to see is something like this 

 WHERE ( `Carac_d`.`id_devis` LIKE '721' ) AND (( `Carac_d`.`num_piece` LIKE '2' ) OR ( `Carac_d`.`num_piece` LIKE '3' ) ;

Should i modify the separator in the num_piece field, or should i do a custom php where clause ?

Or should i  do a custom php which cause the read data to have every field loaded?

return [["field", "value", "="], "OR", ["field", "xxx", "="]];

return [["field", "value", "=="], "AND", ["field2", "xxx", "!="]];
where_clause.png
Max_admin Max_admin 21 Jan, 2025
Answer

I think a custom PHP where is better and I think you need an IN clause, not LIKE

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
fa fabrice.witkowski758 23 Jan, 2025
1 Likes

the in statement only show the first id. so i use a cutom php action to replace the read db actions and this works for me. For the sql command, i use the one which is shon on my debug tab ans directly modify it.

the data are available in the model as the read data should do. 

Thanks for your answer, it has made me to do the right choice quickly.

Max_admin Max_admin 23 Jan, 2025

great, please note that in v8 you write the WHERE statement manually which gives you the freedom to do what you need

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.