두 테이블이 있습니다 messages
및 thread
받은 편지함에 새 메시지를 messages
테이블에서 표시하고 있습니다. 대화가 시작되면 나는 Facebook이하는 것처럼 1 new message
을 보여주고 싶습니다. 대화를 시작하면 1 개의 새로운 2 개의 새로운 코드가 표시됩니다. 아래 코드는 표시되지 않습니다. 그것은 messages
테이블의 id
이 messages
테이블의 각 행에 대해 읽지 않은 메시지의 thread_message_id
thread
의 테이블, 쇼 번호와 일치하면 내가 원하는 것은 나를 undefined index thread_id
새 메시지에 대한 알림 표시
에게 제공합니다. 아래 이미지 (그냥 1 NEW
라고 입력)와 마찬가지로 각 행에 대해 읽지 않은 메시지 수를 표시하고 싶습니다. 아무도 아이디어가 있습니까?
$stmt = $msg->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->error;
$stmt->bind_param('sss....', $username......);
$stmt->execute();
//I did new select query to get the thread_message_id
$thread = $msg->prepare("SELECT * FROM thread where thread_to_user = ? and thread_is_read = '0'");
echo $msg->error;
$thread->bind_param('s', $username->username);
$thread->execute();
$thread_unread = $thread->get_result();
while ($row = $thread_unread->fetch_assoc()) {
$thread_id = $row['thread_message_id'];
}
while ($row = $max->fetch_assoc()) {
if($thread_id == $row['id'] && $thread->num_rows > 0){echo "<div class='m_new'>".$thread->num_rows." New"."</div>";}
?>
즉시 업데이트하지 말고 페이지 새로 고침시 부모 ID와 관련된 읽지 않은 메시지를 표시하고 싶습니다. – user3006683