Forums

Problems with building DB read statsement

Elita- 03 Jan, 2025

Hi, Max, is it bug? when I try to build a where statement  - access IN {data:access_levels} I get an array in Quotes and double quotes? 

[access_levels] => Array
        (
            [0] => 11
            [1] => 12
            [2] => 13
            [3] => 7
            [4] => 14
            [5] => 9
            [6] => 8
            [7] => 10
            [8] => 6
        )
[read_data4] => Array
        (
            [********] => SELECT * FROM `` WHERE access IN ["'11'","'12'","'13'","'7'","'14'","'9'","'8'","'10'","'6'"]
            [returned] => 
                (
                )

        )

)
Max_admin 04 Jan, 2025
Answer

array values are auto converted to json encoded array by default, which is what you have here

you will need to use PHP to build the IN array(you can run PHP code in the WHERE box), or wait for the next update and use {data.in:access_levels}

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 06 Jan, 2025

Max,

I have already created an array in PHP - [access_levels] - and I’m using it in an IN clause for a database query.

The issue is that this IN array contains both single and double quotes:

["'11'", "'12'", "'13'", "'7'", "'14'", "'9'", "'8'", "'10'", "'6'"]

As a result, the IN clause isn’t working correctly.

In CF6, I resolved this by converting the array into a format suitable for the IN query using the {val:} placeholder and placing the resulting values in DATA.

In CF8, this workaround didd not seem necessary anymore. Should I apply the same approach, or is there a better way to handle this in CF8?

Max_admin 08 Jan, 2025

Hi Elita

The IN array should be like this:

('11', '12', '13')

You can build this and use it OR wait for the next update and use 

{data.in:access_levels}

if you have another solution which works then you can use it of course

Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
Elita- 08 Jan, 2025
1 Likes

Thanks, Max. That was my intention - to draw your attention to this. I'm very much looking forward to using it as a built-in function of CF8.

Sincerely, Elita

You need to login to be able to post a reply.