Note that there are some explanatory texts on larger screens.

plurals
  1. POShowing notification for new messages
    primarykey
    data
    text
    <p>I have two tables <code>messages</code> and <code>thread</code> I am displaying new messages in inbox from <code>messages</code> table. If conversation is started I would like to show <code>1 new message</code> just like the way Facebook does. When you start a conversation and it shows 1 new, 2 new... The code I have below doesn't show. It gives me <code>undefined index thread_id</code></p> <p>What I want is if the <code>id</code> of the <code>messages</code> table match the <code>thread_message_id</code> of <code>thread</code> table, show number of unread messages for each row in the <code>messages</code> table. As on the below image(I just put <code>1 NEW</code> myself), I want to show the number of unread messages for each row. <img src="https://i.stack.imgur.com/hUIku.png" alt="Here is the image"> Does anyone have any idea?</p> <pre><code>$stmt = $msg-&gt;prepare( "SELECT id, to_user, from_user, message, is_read, date, subject, orig_sender, conversation FROM ( SELECT m.id, max(t.thread_id) thread_id, m.to_user, m.from_user, m.message, m.is_read, m.date, m.subject, m.orig_sender, m.conversation FROM messages m LEFT JOIN thread t on(t.thread_message_id = m.id) WHERE ( m.to_user = ? AND m.deleted != ? AND m.del2 != ?) OR (m.from_user = ? AND m.conversation = 'true' AND m.deleted != ? AND m.del2 != ?) GROUP BY m.id ORDER BY m.conversation asc, thread_id desc ) tbl"); echo $msg-&gt;error; $stmt-&gt;bind_param('sss....', $username......); $stmt-&gt;execute(); //I did new select query to get the thread_message_id $thread = $msg-&gt;prepare("SELECT * FROM thread where thread_to_user = ? and thread_is_read = '0'"); echo $msg-&gt;error; $thread-&gt;bind_param('s', $username-&gt;username ); $thread-&gt;execute(); $thread_unread = $thread-&gt;get_result(); while ($row = $thread_unread-&gt;fetch_assoc()) { $thread_id = $row['thread_message_id']; } while ($row = $max-&gt;fetch_assoc()) { if($thread_id == $row['id'] &amp;&amp; $thread-&gt;num_rows &gt; 0){echo "&lt;div class='m_new'&gt;".$thread-&gt;num_rows."&amp;nbsp;New"."&lt;/div&gt;";} ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload