php - Foreach loop - receiving duplicates -



php - Foreach loop - receiving duplicates -

wonder if assist me below. have created foreach loop show children pages of current page. works.

i trying show different text each kid based on whether current logged in user owner or not. works, apart @ each loop iteration previous results added prior current.

<?php $results = $page->children; foreach($results $reply) { //bottom post buttin display options - reply if ($reply->createduser->name == $user->name){ $bottom_options_reply .= "<p> current owner</p>"; } else { $bottom_options_reply .= "<p> not 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 screenshot of output.

$bottom_options_reply appending each time in foreach

try:

//bottom post buttin display options - reply $bottom_options_reply = ''; //this reset if ($reply->createduser->name == $user->name){

or remove . if you're not going utilize variable else before it

php

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -