graham23s Posted June 26, 2007 Share Posted June 26, 2007 Hey guys, in this simple bit of code i query the database for user pm's , i do a while loop to see if any of the messages in the inbox are unread (Enum Y/N) because it's in the loop if i have 5 unread messages it says i have 5 unread messages 5 times is there a way i can query the db but only display the unread messages output once to the user: // check if the user has messages in there inbox...///////////////////////////////// $query_msg = "SELECT * FROM `pms` WHERE `reciever_id`='$id'"; $result_msg = mysql_query($query_msg) or die (mysql_error()); if (mysql_num_rows($result_msg) > 0) { echo '<br /> <table border="1" bordercolor="#000000" cellspacing="0" cellpadding="10" bgcolor="red"> <tr> <td style="padding: 10px; background: red"> <strong><a class="msg_inbox" href="inbox.php">You Have Messages In Your Inbox</a> </td> </tr> </table>'; } while($rows = mysql_fetch_array($result_msg)) { $read = $rows['read_flag']; // unread messages? ...///////////////////////////////////////////////////////////// if ($read == 'N') { echo '<br /> <table border="1" bordercolor="#000000" cellspacing="0" cellpadding="10" bgcolor="red"> <tr> <td style="padding: 10px; background: blue"> <strong><a href="inbox.php"><font color="#ffffff" />Some Of These Messages Are Unread</font></a> </td> </tr> </table>'; } } thanks for any help Graham Quote Link to comment Share on other sites More sharing options...
Pastulio Posted June 26, 2007 Share Posted June 26, 2007 <?php $query_msg = "SELECT * FROM `pms` WHERE `reciever_id`='$id' AND `read_flag` = 'N'"; $result_msg = mysql_query($query_msg) or die (mysql_error()); $num_rows = mysql_num_rows ($result_msg); if ($num_rows == 1){ echo "you have 1 new message."; } elseif ($num_rows > 1) { echo "you have " . $num_rows . " new messages."; } ?> I think this will do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.