Jump to content

Foreach loop - receiving duplicates


ankh2054
 Share

Recommended Posts

Hi All,

Wonder if someone could assist me with the below. I have created a foreach loop to show all the children pages of current page. This works.

I am then trying to show different text for each child based on whether the current logged in user is the owner or not. This works, apart from at each loop iteration the previous results are added prior to the current.

<?php 

            $results = $page->children;

            foreach($results as $reply) { 

                //Bottom post buttin display options - Reply
                if ($reply->createdUser->name == $user->name){

                    $bottom_options_reply .= "<p> This is the current owner</p>";

                }

                else  {

                    $bottom_options_reply .= "<p> This is not the owner </p>";
                }

                //Theme each topic                   
                echo " 
                    
        <div class='panel panel-default'>
                    
                        <div class='panel-body'>
                             <div class='col-md-3'>
                                {$avatar_profile_logo}
                                {$reply->createdUser->name}
                             </div>
                             <div class='col-md-6'>
                                {$reply->body}
                             </div>
                        </div>
                   

                    <div class='panel-footer'>
                       
                        {$bottom_options_reply}
                        
                    </div>
               
               
        </div>
                ";

Below is the screenshot of the results, showing the $bottom_options_reply being added multiple times. 

post-2239-0-40995000-1403262217_thumb.pn

Link to comment
Share on other sites

I added this to the above and it worked. 

$bottom_options_reply = '';

//Footer button display options - Reply
                $bottom_options_reply  = '';
                if ($reply->createdUser->name == $user->name){

                    $bottom_options_reply .= "<p> This is the current owner</p>";

                }
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...