Forums

Extract field from array with "Loop" function

johnny64 30 Apr, 2020
Hi, with the help of your wonderful application Chronoforms v6 I have created a form that allows me to extract data from a database, specifically Bible verses starting from book and chapter. The output variable is obviously an array of data and I need to show only the field of my interest called "TestoLuzzi" on the screen. I tried using the "Loop" function by setting the Data Provider, as you suggested on page 28 of your Manual, with {data: dataluzzi} where dataluzzi is the name of the array containing the data and "Loop body" with {var : loop104} where loop104 is the name of the loop. This way I don't have any output data. Then I tried to set the Data Provider {var: dataluzzi} keeping "Loop body" {var: loop104} and in this case returned the output the string {"row":{"dataluzzi":{"TestoLuzzi":"[x] yyyy "}},"key":z}. I tried with {var: loop104.row.TestoLuzzi} in the "Loop body" but I have no results in the output. The question is: how can I go about having only the data of the field of my interest output (TestoLuzzi)? Thanks for your interest and valuable advice.
johnny64 03 May, 2020
Sorry, have I been offensive to anyone being ignored? Thanks
Max_admin 03 May, 2020
it depends on the structure of your array, the syntax is:
{var:loop_name.row.sub_element}
Where "loop_name" is the name of the Loop action and "sub_element" is the name of a sub element key
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
johnny64 04 May, 2020
Thanks Max for your kind reply. I had already tried the solution you suggested to me but to no avail!
- The "Read data" function has the "Model name" = "dataluzzi" and is set to return an array with a pair of values;
- The array variable is correctly generated and contains the sub-element "Verso" and "Testo";
- I tried the "Loop" function with "Name" = "estrazione" by setting the "Data Provider" the first time {data:dataluzzi} and the second time with {var:dataluzzi} and in both cases with "Loop body" = {var:estrazione.row.Testo} and also alternatively selecting the switch "Return the result as var?" in ON and OFF. (See file Image_ReadData1.jpg, Image_ReadData2.jpg).
Unfortunately it comes that is generated is the one visible in the file "Image_OUTPUT.jpg"
I am available to provide administrator access to the site for any checks. Thank you so much for the help you will offer me.

johnny64 07 May, 2020
Hi,
could I get some help? If I haven't explained the problem enough, I can try again. Thanks
healyhatman 08 May, 2020
In the loop, you want {var:name_of_the_loop_function.row.name_of_the_data_model.name_of_the_field}
The data source for the loop should be {var:name_of_read_data_function}
johnny64 09 May, 2020
healyhatman Thank you for your suggestion. Unfortunately as you can see from the pictures it doesn't work. How to find the solution? Can it depend on the version of PHP? My version of PHP is 7.3.8.
Thanks in advance for further suggestions.
healyhatman 09 May, 2020
Why are you retrieving array of key value pairs?

Just put {var:loopnamehere.row} to see the data available each loop
johnny64 12 May, 2020
Hi healyhatman,
I can't get out of it! I selected the type "Index the results list by one or more fields values." But nothing has changed. I am available to give administrator access to understand what is wrong: Thanks for your help
healyhatman 12 May, 2020
Just select the data normally
johnny64 12 May, 2020
Answer
WOW ... wonderful !!!
Many Thanks healyhatman!
As you said it was enough to set Select type in "All matching records" to get the desired data on the output!
Thanks for your availability and your kindness. See you soon.
This topic is locked and no more replies can be posted.