graham23s Posted August 2, 2009 Share Posted August 2, 2009 Hi Guys, I just wrote this basic code to check whether there are unread messages in the message table if there is then a javascript popup tells me so: <?php // Check to see if there are unread messages and display message to raz $qm = "SELECT * FROM `fcp_contact_messages` WHERE `message_filed`='N'"; $rm = mysql_query($qm) or die (mysql_error()); // Loop while ($am = mysql_fetch_array($rm)) { // Message flag $mFlag = $am['message_read']; // if ($mFlag == "N") { // Set a boolean $messagesUnread = true; } // if (isset($messagesUnread)) { print "<script type='text/javascript'>alert('There are unread message(s) in the inbox.')</script>"; } } ?> The code works fine but the problem is if there is 10 unread messages then i get 10 popups, i was just really wanting the 1 popup. i can't see what i can do to fix this. any help would be appreciated. thanks guys Graham Link to comment https://forums.phpfreaks.com/topic/168487-limiting-messages/ Share on other sites More sharing options...
Bricktop Posted August 2, 2009 Share Posted August 2, 2009 Hi Graham, It's because the check for a read message is inside the WHILE loop. Get rid of the WHILE loop and try again. Something like: <?php // Check to see if there are unread messages and display message to raz $qm = "SELECT * FROM `fcp_contact_messages` WHERE `message_filed`='N'"; $rm = mysql_query($qm) or die (mysql_error()); $am = mysql_fetch_array($rm); // Message flag $mFlag = $am['message_read']; // if ($mFlag == "N") { // Set a boolean $messagesUnread = true; } // if (isset($messagesUnread)) { print "<script type='text/javascript'>alert('There are unread message(s) in the inbox.')</script>"; } ?> Link to comment https://forums.phpfreaks.com/topic/168487-limiting-messages/#findComment-888807 Share on other sites More sharing options...
graham23s Posted August 2, 2009 Author Share Posted August 2, 2009 darn so it is lol, geez it's to early for me lol thanks mate i took it out the while loop and all is good thanks again mate Graham Link to comment https://forums.phpfreaks.com/topic/168487-limiting-messages/#findComment-888810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.