我有一个问题。此代码很好地计算新消息,但重播消息未显示该数字。 例如:10条消息(6条新消息+ 4条重播消息) 现在显示6条消息。 应该显示10条消息。 该表是带有列的消息:
message_id | message_thread_code |消息|发件人|时间戳| READ_STATUS
第二个表是message_thread,其中包含列:
message_thread_id | message_thread_code |发件人|收货人| last_message_timestamp
<!-- message number apper count per user // START -->
<?php
$current_user = $this->session->userdata('login_type') . '-' . $this->session->userdata('login_user_id');
$this->db->where('message_thread.reciever', $current_user);
$this->db->where('message.read_status', 0);
$this->db->from('message_thread');
$this->db->join('message', 'message.message_thread_code = message_thread.message_thread_code');
$unread_message_number = $this->db->count_all_results();
?>
<a href="<?php echo base_url();?>index.php?admin/message">
<i class="entypo-mail"></i>
Casuta mesaje
<span class="badge badge-secondary"><?php echo $unread_message_number; ?></span>
<!-- message number apper count per user // FINISH -->
The controller:
function count_unread_message_of_thread($message_thread_code) {
$unread_message_counter = 0;
$current_user = $this->session->userdata('login_type') . '-' . $this->session->userdata('login_user_id');
$messages = $this->db->get_where('message', array('message_thread_code' => $message_thread_code))->result_array();
foreach ($messages as $row) {
if ($row['sender'] != $current_user && $row['read_status'] == '0')
$unread_message_counter++;
}
return $unread_message_counter;
}