Jump to content

Limiting messages


graham23s

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.