I have a large php string variable. I want to put php if/else condition inside it, so the edit and delete buttons to be displayed only to the author of the comment and not to everyone, but my code is not working. I used a colon to define the if/else condition, but it doesn’t work. Regular if/else condition also doesn’t work.
Here is my php code:
$user_id = $_SESSION['user_id'];
$if = "if ($user_id == $row['user_id']): ";
$else = "else: ";
$endif = "endif; ";
foreach($result as $row)
{
$output .= '
<div class="panel panel-default">
<div class="panel-body">'.$row["comment"].'</div>
<div class="panel-footer">
'. $if .'
<form class="input-group form-row" action="comment_delete1.php" method="post" enctype = "multipart/form-data">
<div class="input-group-prepend">
<input type="hidden" name="comment_id" id="comment_id" value="'.$row["comment_id"].'" />
<input type="hidden" name="user_id" id="user_id" value="'.$row["user_id"].'" />
<input type="submit" name="submit" id="submit" class="submit btn btn-default" value="Delete" />
</div>
</form>
<button type="button" class="btn btn-default edit" id="'.$row["comment_id"].'" >Edit</button>
'. $else .'
<button type="button" class="btn btn-default reply" id="'.$row["comment_id"].'" >Reply</button>
'. $endif .'
</div>
</div>
';
}
echo $output;