Jump to content

Problem Display Error


Mod-Jay

Recommended Posts

I am making a script that has a Notification/Inbox system in it. Right know it's close to being done, but I have one problem..

 

My problem is that if a user has >= 1 message in their inbox it shows what it should, but if the user has nothing in the inbox it shows nothing instead of the simple error "You have no message in your inbox".

 

Code 1:

        $inbox_a = mysql_query("SELECT * FROM notifications WHERE recieverid='". $_SESSION['id'] ."'") or die(mysql_error());

 

Code 2:

			<?php if(!mysql_num_rows($inbox_a) <= 0) { ?>
				<tr class="table">
					<td class="name"><a href="usercp.php?usercp=inbox&id=<?php echo $msgid; ?>"><h3><?php echo ucFirst($msgname); ?></h3></td>
					<td class="revision"><h3><a href="#"><?php echo $msgsendername ?></a></h3></td>			
					<td class="votes"><h3><?php echo date('D, M d, Y h:i A', strtotime($msgdate)) ?></h3></td>						
				</tr>
		<?php } else { ?>
				<tr class="table">
					<td class="name">You have no messages in your inbox.</td>
					<td class="revision"></td>			
					<td class="votes"></td>						
				</tr>
		<?php } ?>

 

 

Link to comment
Share on other sites

If the code you did post is inside of a loop, it won't work, no matter what logic you use, because the code inside the loop is not executed when there are zero rows in the result set.

 

You must test before the start of the loop if there are rows or not and print your "You have no messages ..." if there are no rows and execute the loop if there are rows.

Link to comment
Share on other sites

Then use a loop

 

<?php if(mysql_num_rows($inbox_a) ) { ?>
<?php while($row = mysql_fetch_array($inbox_a)){ ?>
<tr class="table">
<td class="name"><a href="usercp.php?usercp=inbox&id=<?php echo $row['msgid']; ?>"><h3><?php echo ucFirst($row['msgname']); ?></h3></td>
<td class="revision"><h3><a href="#"><?php echo $row['msgsendername']; ?></a></h3></td>
<td class="votes"><h3><?php echo date('D, M d, Y h:i A', strtotime($row['msgdate'])) ?></h3></td>
</tr>
<?php }} else { ?>
<tr class="table">
<td class="name">You have no messages in your inbox.</td>
<td class="revision"></td>
<td class="votes"></td>
</tr>
<?php } ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.