There is such a table how to change it so that you can count the number of new messages for each user:
user_id admin_id subject text
Hello
First of all, you need to add a column to your table like: active
If this line equals 1, the message is Unread.
After that, we can use this code, (I will do it in sessions) :
<?php session_start(); $sql = mysql_query("SELECT * FROM message WHERE user_id='".$_SESSION['user_id']."' AND active='1'"); if(mysql_nuw_rows($sql) > 0){ echo "У Вас новых сообщений: ".mysql_nuw_rows($sql); } ?>
Code Explanations:
message
- This is your message table.mysql_nuw_rows()
- Returns the number of rows.I hope that I clearly stated :)
active = 1
is a terribly unthinkable name / value. Better to somehow beat the words read, shown or something else like that. IMHO, of course. - xEdelweissOn good, you should have at least two tables:
1) Таблица пользователей(и админов тоже): user_id, user_type и т.д. 2) Таблица сообщений: message_id, message_text, message_status, sender_id, reciever_id
Information about the readability of the message is stored in message_status.
In general, there is such a thing as normal forms, and so I remember it very vaguely. Perhaps it would be much more intelligent to make 3 tables.
UPD: Number of new posts:
SELECT COUNT(*) FROM message_table WHERE reciever_id = user_id AND message_status = 0
user_id - ID of the user whose messages we count
message_status = 0, provided that 0 means unread message, and -1 read
Source: https://ru.stackoverflow.com/questions/202115/
All Articles