'if statement inside concatenation
If the user is verified then a verified icon must be shown next to the comment author
<?php if($data->verified): ?><i class="fa fa-check-circle"></i><?php endif;?>
The comment section code :
while($data = $result->fetch_object()) {
$content .= '
<div class="caption animated fadeIn">
<a href="profile/' . $data->username . '"><img src="' . self::display_image(AVATARS_THUMBS_ROUTE . $data->avatar) . '" class="img-circle dashboard-avatar" alt="Avatar"/></a> <a href="profile/' . $data->username . '">' . $data->name . '</a><span>' . Messages::generate_emoticons(User::generate_links($data->content)) . '</span>
</div>
';
}
Solution 1:[1]
Simply put the HTML in a variable, make it empty when you need, and concatenate it like you do with the rest:
while($data = $result->fetch_object()) {
if($data->verified) {
$icon = '<i class="fa fa-check-circle"></i>';
} else {
$icon = '';
}
$content .= '
<div class="caption animated fadeIn">
<a href="profile/' . $data->username . '">'.$icon.'<img src="' . self::display_image(AVATARS_THUMBS_ROUTE . $data->avatar) . '" class="img-circle dashboard-avatar" alt="Avatar"/></a> <a href="profile/' . $data->username . '">' . $data->name . '</a><span>' . Messages::generate_emoticons(User::generate_links($data->content)) . '</span>
</div>
';
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Funk Forty Niner |