Answer the question
In order to leave comments, you need to log in
How to implement a notification system in a PHP project?
notifications like "message received from %user%", "customer confirmed payment for order No. %order_id%"
I think to make an events table with a user_id foreign key, when inserting into the messages table we make an entry in the events table, in the client code a simple ajax that makes a request once a minute and check the events table, after receiving it saves the id of the last received message.
how much is correct? this is not a real-time system and a simple solution is needed, so it makes no sense to implement comet, websockets, sse
Answer the question
In order to leave comments, you need to log in
Yes, it’s quite right for myself, I recently had the same task, it didn’t reach the implementation (the client dropped the project), but I thought to do the same as you did.
If I understood correctly, then you can do without events , since everything is in your messages , just specify the key "read", "date-time" .
After in php, with ajax access, make a selection on not-"read" .
The last received message from a specific user can also be obtained, also without an extra table,
SELECT * FROM `messages` WHERE `user_id`='1' ORDER BY `Id` DESC LIMIT 0,1;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question