Using loop to populate a table with data array

cbahiana 05 Nov, 2018
I have a form that collects data from respondents and saves it to a table. This is working fine and an e-mal is being correctly sent with the corresponding data.

Now I need to send an e-mail at the first day of every month with all the data of the last month, as a report.

In the "Setup" tab of a new form I created a "Read Data" (read_data7) at "Load" and gave it "Mes" as Model name. It selects "all matching records" from the database table populated by the other form. For now I am not using the WHERE statement, but restricted "Fields to retrieve" to "Mes.usuario" and "Mes.km", so it produces the following array:
Array
(
    [option] => com_chronoforms6
    [cont] => manager
    [chronoform] => relatorio-mensal
    [__utma] => 211587479.1106122593.1507028339.1515270305.1515276943.34
    [__cfduid] => d6ba1cdb6461b2d61f14c50fd99bee56b1522380223
    [b95cb515caaa6a620dd96e25e0c42b43] => 509788288fe07d8f7befbe9a8461d5f8
)
Array
(
    [read_data7] => Array
        (
            [log] => Array
                (
                    [0] => SELECT `Mes`.`usuario` AS `Mes.usuario`, `Mes`.`km` AS `Mes.km` FROM `fz7dk_chronoforms_data_voluntarios` AS `Mes` LIMIT 100;
                )

            [var] => Array
                (
                    [0] => Array
                        (
                            [Mes] => Array
                                (
                                    [usuario] => Super User
                                    [km] => 169680
                                )

                        )

                    [1] => Array
                        (
                            [Mes] => Array
                                (
                                    [usuario] => Carlos Bahiana
                                    [km] => 5
                                )

                        )

                    [2] => Array
                        (
                            [Mes] => Array
                                (
                                    [usuario] => Carlos Bahiana
                                    [km] => 13
                                )

                        )

                    [3] => Array
                        (
                            [Mes] => Array
                                (
                                    [usuario] => Carlos Bahiana
                                    [km] => 20
                                )

                        )

                )

        )

)

I need to both show at the website and send an e-mail with the corresponding table. To do so I decided to use Loop (loop8) also at Setup load. It's "Data Provider" is set to {data:Mes} and the loop body is

<tr><td>{var:loop8.row.usuario}</td><td>{var:loop8.row.km}</td></tr>

and "Return the result as var?" is set to yes.

Still at the Setup load I included an Email action with the table in the body:

<table>
<caption>Relatório de {date:d/m/Y}</caption>
<thead>
<tr>
<th>Voluntário</th>
<th>Km</th>
</tr>
</thead>
<tbody>
{var:loop8}
</tbody>
</table>

The e-mal is being sent, but it brings table with it's caption and thead, but no data:

Relatório de 05/11/2018
Voluntário Km

At the Design tab I created a custom HTML:

<table>
<caption>Relatório de {date:d/m/Y}</caption>
<thead>
<tr>
<th>Voluntário</th>
<th>Km</th>
</tr>
</thead>
<tbody>
{var:loop8}
</tbody>
</table>

but it also doesn't include the Loop's body, not even the HTML tags.

It probably is something stupid, but I just can't make it work. Can you help me?
healyhatman 06 Nov, 2018
Is this the same question I answered already earlier?

Set data provider to {var:read_data7}

And each loop get the data with {var:loop8.row.Mes.field}
cbahiana 06 Nov, 2018
Thank you, healyhatman, that did it!

I was following the examples on the cf6manual-1.0.2.pdf, which clearly illustrates, on page 28, to use {data:Model} as Data Provider and {var:loop6.row.model}. These would translate to {data:Mes}, {var.loop8.row.usuario} and {var:loop8.row.km}, respectively, in my case.

Maybe the answer that you gave earlier might have been for a similar case, someone who was following the same instructions.
This topic is locked and no more replies can be posted.