[résolu]Boucle sur champ à valeurs multiples

More
11 years 6 months ago - 11 years 6 months ago #36381 by V@lentine
Hello,

J'ai quelques difficultés avec l'affichage d'un champ "debut_session" pour lequel je peux avoir plusieurs valeurs.
C'est un champ dans lequel je stocke des sessions de formation sous cette forme "référence|dates|lieu"
Donc une formation peut avoir plusieurs sessions.

Voici mon code, mais au final seule la première session est visible :
Code:
<div id="sessions"> <?php if (isset($this->item->positions['sessions'])) : ?> <table style="width:100%;"><tr> <th>R&eacute;f.</th><th>Dates</th><th>Lieu</th><th>Inscription</th></tr> <?php foreach ($this->item->positions['sessions'] as $champ) : ?> <tr> <?php $t=''; for($i=0 ;$i<(strlen($tarif)-1);$i++){ if(preg_match('#^[0-9]#',$tarif[$i])) $t.=$tarif[$i]; } $td=$t/100; $tarif=number_format($td,2,',',' '); ?> <?php $stage=explode('|',$champ->display); ?> <td> <?php echo $stage[0]; ?></td><td><?php echo $stage[1]; ?></td><td><?php echo $stage[2]; ?></td> <td>[url=<?php echo $pageURL.'/175-demande-de-renseignements?dates='.$champ->display.'&formation='.$this->item->title.'&tarif='.$tarif.'&doc='.$doc; ?>]Candidature[/url]</td> </tr> <?php endforeach; ?> </table> <?php endif; ?> </div>

Merci
Last edit: 11 years 6 months ago by V@lentine.

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #36397 by ggppdk
Hello
What is the type of the field?
What do you mean by "sessions" ?
Are you reporting a bug ? or other question?


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #36415 by V@lentine
Hello,

ggppdk wrote: Are you reporting a bug ? or other question?

It's not a bug, it's just that I need help with my code.

ggppdk wrote: What is the type of the field?

My field is a text field.

ggppdk wrote: What do you mean by "sessions" ?

For a training course (e.g. Microsoft Access) we can have one or more sessions (e.g. one in February, one in May, one in September...).
Each of these sessions has a reference, dates and takes place somewhere.
As I didn't want to have as many "Access" items as sessions, I use a text field with multiple values, separating the 3 datas like this :
reference|dates|place
e.g; for "Access" I have :
13506|du 2 au 5 février 2013|Mulhouse
13507|du 16 au 19 mai 2013|Mulhouse
13508|les 4, 9 et 10 septembre 2014|Mulhouse


Now I want to display my sessions at the bottom of my content in a table, with a link for each of them to my chronoforms (submission form).

The problem I have is that I only get the first session. Trouble with foreach I suppose, but I'm not quite at ease with the coding for flexi...
It must be here :
Code:
<?php foreach ($this->item->[b]positions['sessions'][/b] as $champ) : ?>
I don't know how to get my field's values...

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #36437 by ggppdk
Hello,

13508|les 4, 9 et 10 septembre 2014|Mulhouse


-- where did you define the above ? in chronoforms?

-- in PHP code the 'sessions' is custom field position of a FLEXIcontent custom template?
if so, which field(s) did you place there?


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #36439 by V@lentine
My field's name is debut_session
It has several values possible and I want to display them all

Please Log in or Create an account to join the conversation.

More
11 years 6 months ago #36493 by V@lentine
Hello,

Sorry to be so brief, I answered from my mobile phone...
Here is a visual example of what I'm doing.
You can see at the bottom the table containing the training sessions. There is only one row where there should be 2 :

[attachment=1:gmatqkp6]<!-- ia1 -->access.jpg<!-- ia1 -->[/attachment:gmatqkp6]
And my template's code for this table :
Code:
<div id="sessions"> <?php if (isset($this->item->positions['sessions'])) : ?> <table style="width:100%;"><tr> <th>R&eacute;f.</th><th>Dates</th><th>Lieu</th><th>Inscription</th></tr> <?php foreach ($this->item->positions['sessions'] as $champ) : ?> <tr> <?php $stage=explode('|',$champ->display); ?> <td> <?php echo $stage[0]; ?></td><td><?php echo $stage[1]; ?></td><td><?php echo $stage[2]; ?></td> <td>[url=<?php echo $pageURL.'/175-demande-de-renseignements?dates='.$champ->display.'&formation='.$this->item->title.'&tarif='.$tarif.'&doc='.$doc; ?>]Candidature[/url]</td> </tr> <?php endforeach; ?> </table> <?php endif; ?> </div>

I supposed that this line :
Code:
foreach ($this->item->positions['sessions'] as $champ)
was reading every value of the field "debut_session" but it's reading only the first value. I want to know how to read all values.
[attachment=0:gmatqkp6]<!-- ia0 -->debut_session.jpg<!-- ia0 -->[/attachment:gmatqkp6]
$champ->name is the name of the field
$champ->label is the label of the field
but what for the multiple values ?

Thanks
Attachments:

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.353 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline