title: How to maintain read/unread messages by php
body: <p>This question might have been asked many times before this post, but I could not find a suitable answer which perfectly did what I want.</p>
  
  <p>Suppose I have two tables:</p>
  
  <pre><code>table-1: table_msg
  -------------------------------------------------------
   msg_id |       msg_subject       | create_time
  -------------------------------------------------------
      1   | welcome to this site    | 2015-01-01 10:20:30
  -------------------------------------------------------
      2   | How to visit this site  | 2015-01-05 10:30:00
  --------------------------------------------------------
      3   | Plz pay your member fee | 2015-03-10 09:00:00
  --------------------------------------------------------
      4   | Important Notice        | 2015-06-01 12:20:00
  --------------------------------------------------------
      5   | Plz change your password| 2015-06-15 13:24:01
  --------------------------------------------------------
  
  
  table-2: table_user
      -------------------------------
       user_id |    last_login
      -------------------------------
          1    | 2015-03-01 07:00:00
      -------------------------------
  </code></pre>
  
  <p>I see solutions almost all the time, that as <code>user_id-1</code>'s last login was before <code>msg_id-3</code>, so if the <code>user_id-1</code> logins on <code>2015-06-02</code>, he has 02 new messages <code>msg_id-3</code> and <code>msg_id-4</code>. Well I can bold the subject of these two messages by css to show it as <code>UNREAD</code>. Now suppose after login <code>user_id-1</code> opened <code>msg_id-4</code> and did not opened <code>msg_id-3</code>, so the <code>msg_id-3</code> is still <code>UNREAD</code>. </p>
  
  <p>Now when the same user again login on <code>2015-06-20</code>, then after his last login, <code>msg_id-5</code> can be easily identified as <code>UNREAD</code> as it was posted after his last login <code>2015-06-02</code>, it can be made bold, but what about <code>msg_id-3</code> which was posted before his last login but still not opened. It is also <code>UNREAD</code> and should be in Bold font. </p>
  
  <p>How can I identify <code>msg_id-3</code> as <code>UNREAD</code> without a separate table like below:</p>
  
  <pre><code>table-3: read_msg
  ------------------------
   id | user_id | msg_id
  ------------------------
    1 |    1    |    1
  ------------------------
    1 |    1    |    2
  ------------------------
    1 |    1    |    4
  ------------------------
  </code></pre>
  
  <p><code>table-3</code> is well for a few users, but if users are 5000 in numbers and total messages are 10000 or higher then the table would be a quite large to handle for mysql engine and it will grow geometrically larger even day by day.</p>
  
  <p>Is there any mechanism/technique or algorithm so that together with message that were posted after last login, message which were not opened before last login can also be identified as <code>UNREAD</code> without a huge size <code>read_msg</code> table? </p>