Jump to content
felted

Repeater with five fields generates sixten outputs

Recommended Posts

Hi,

i have tow repeaters on a site with five fields.

 

foreach ($child->Portrait_Repeater as $data) {
					$i = 1;
					foreach($data as $person_data){
						$content .= $i.": ".$person_data."<br />";						
						$i++;
					}
	}

The foreach outputs sixten fields:

1: 1113
2: 1570437779-0381-1
3: 1
4: 0
5: 0
6: sort
7: 41
8: 41
9: 1570437779
10: 1570439027
11: 1570437833
12: max.jpg
13: Max Mustermann
14: Rektor
15: 1234 - 56789
16: info@maxundmoritz.de

Where are the first 11 fields coming from?

Thanks, Detlef

Share this post


Link to post
Share on other sites

Behind the scenes, repeater entries are individual pages, so when you iterate over an entry (your second loop), you iterate over all the properties of the repeater page. You can see that if you change your code to:

foreach ($child->Portrait_Repeater as $data) {
					$i = 1;
					foreach($data as $prop => $person_data){
						$content .= $i.": $prop => ".$person_data."<br />";						
						$i++;
					}
	}

The solution is to remove the inner loop and address the properties by name instead, like $person_data->email, $person_data->position etc.

  • Like 3
  • Thanks 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...