Jump to content

private message code


graham23s

Recommended Posts

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

Link to comment
Share on other sites

<?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.

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.