Reputation: 97
I've added an if statement inside my while loop to show specific data to a specific user, but I would like to add an ELSE statement of echo"No Notifications";
. Only it prints this text out over and over for the amount of times I've asked the loop to print results out in the SQL query. How can I stop this so it just shows the else statement the once inside the <div class="notif_ui">
div?
while($notificationchant=mysqli_fetch_assoc($chant)){
if($_SESSION['id']==$notificationchant['notification_targetuser']){
?>
<div class="notif_ui">
<div class="notif_text">
<div id="notif_actual_text-<? echo $notificationchant['notification_id'] ?>" class="notif_actual_text">
<?
echo "<img border=\"1\" src=\"userimages/cropped".$notificationchant['notification_triggeredby'].".jpg?photo_time=" . time()."\" onerror='this.src=\"userimages/no_profile_img.jpeg\"' width=\"40\" height=\"40\"><a href='".$notificationchant['notification_throughurl']."'>".$notificationchant['notification_content']." </a><br />";
echo "".Agotime($notificationchant['notification_time'])."";
?>
</div>
</div>
</div>
<? }}?>
Upvotes: 0
Views: 82
Reputation: 1082
Create a new variable and set it to 0
$didEcho = 0;
Check if the variable is 0 in your else
else if ($didEcho == 0){
echo 'No Notification';
$didEcho = 1;
}
Then in your else change it to 1
Upvotes: 1