Forums

Explode array and show results in chronoconnectivity V5

simelas 20 Dec, 2015
Hi Bob, Hi Max,
I am trying to figure out how to explode an array in chronoconnectivity V5 such as to show only part of the array content whithin columns list.

e.g. : 'MyField' contains an array . As expected Model.MyField show all data in the array. ( data1,data2,data3,data4, .....)

Is there any way to explode the array to select some of them and put them back in a Model.MyField to display them.

I have tried using pre-display processing or PHP functions, but no success.

Any hint?

Best,

simelas
GreyHead 21 Dec, 2015
Hi simelas,

Technically MyField doesn't contain an array, it contains a comma separated list. You should be able to explode this back into an array using the PHP functions box. The code there would be something like
Model.MyNewField: return explode(',', $cell);
That should give you the array - but I can't work out what you then want to do with the results?

Bob
simelas 21 Dec, 2015
Hi Bob,
thanks for the feed back.
( I missexpressed myself with the array. Yes indeed i was meaning explode a list into an array ...).

The goal is to explode the list in an array such as to use part of the content (of Myfield) and have it displayed in CCV5.

To build on your code: " Model.MyNewField: return explode(',', $cell); " and then display part of $cell content and / or use it for some other stuff.

I'll do some test and let you know about the outcome.

Cheers

Simelas
simelas 21 Dec, 2015
Hi Bob,

me again,

Maybe i should have said that : i have a field which contains A,B,C,D . Goal is to retrieve one of this values and to show it in CCV5 .

Simelas
GreyHead 22 Dec, 2015
Hi Simelas,

How do you know which one to display?

Bob
simelas 22 Dec, 2015
Hi Bob,

In this particular case the data always hold the same position / index, and according to "input" or page to show , i need to retrieve one or other value according to their position in the list ( or in the array when list is exploded)..

With a custom code action in chronoforms as you know, it's pretty simple using for example $form->data['MyArray'][index] , but with CCV5 i have to admit i remain a little bit stuck about how to get the wished data back and show it in CCV5.

Simelas
GreyHead 23 Dec, 2015
Answer
Hi simelas,

If you want say the third element then the code would be something like
Model.MyNewField: $temp = explode(',', $cell); return$temp[2]; 
remembering that the numbering will be 0, 1, 2, . . .

Bob
simelas 29 Apr, 2016
Hi Bob ,

Back to this project.

works fine. Thanks for the hint.
Cheers !
This topic is locked and no more replies can be posted.