shadowayex Posted June 1, 2008 Share Posted June 1, 2008 I built a messaging system for a website I'm building. So far I've been successful at everything I add to it. But I want to add a script that will show "Box is empty" is there's no messages. This is the code that gets the messages: elseif($mode == "viewinbox") { $inbox = mysql_query("SELECT * FROM messages WHERE Receiver = '$user' ORDER BY MsgId DESC");?> <table><?php while($row = mysql_fetch_array($inbox)) {?> <tr> <td><?php echo $row['Sender']; ?></td> <td><a href="messages.php?mode=viewmsg&id=<?php echo $row['MsgId']; ?>"><?php echo $row['Subject']; ?></a></td> <td><?php echo date('g:i A \o\n F jS, Y', $row['Time']); ?></td> <!-- 150 --> <td><a href="messages.php?mode=deletemsg&id=<?php echo $row['MsgId']; ?>">Delete</a></td> </tr><?php }?> </table> <a href="messages.php?mode=deleteall">Delete All Messages</a><?php mysql_free_result($inbox); } I tried adding a code right after the $inbox part, but It didn't do me any good. I tried two versions, they looked like: if(!$inbox) { die("Box is empty");}------AND------if($inbox == "") { die("Box is empty");} Neither worked. I'm sure that's basically how I'm supposed to do it, but evidently I'm not writing it right. How do I write it? Link to comment Share on other sites More sharing options...
Ingolme Posted June 1, 2008 Share Posted June 1, 2008 if you try to compare $inbox with anything you'll get a string like "Resource #6" or something like that.I don't think you don't need die() for this, after all, if there are no rows nothing else will be written anyways.You use mysql_num_rows() to see how many rows from the database were extracted with the query:if(mysql_num_rows($inbox) == 0) {echo "Box is empty";} Link to comment Share on other sites More sharing options...
shadowayex Posted June 1, 2008 Author Share Posted June 1, 2008 if you try to compare $inbox with anything you'll get a string like "Resource #6" or something like that.I don't think you don't need die() for this, after all, if there are no rows nothing else will be written anyways.You use mysql_num_rows() to see how many rows from the database were extracted with the query:if(mysql_num_rows($inbox) == 0) {echo "Box is empty";} Oh. Seems so easy now. Didn't think about that . Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.