I have following table "friendrequest" in mysql,And i just want whenever User(for example userid=1) recieve any friend request(add row in db again userId) then User should get notification regarding this,How can i do this ?Is this possible with any mysql function ? Here is my table "friendrequest"
id userId friendId
1 1 3
2 1 4
3 1 5
4 2 6
CodePudding user response:
You make no mention of your stack, so, using only PHP and MySQL, you could use websockets for the notifications. http://php.net/manual/en/sockets.examples.php
CodePudding user response:
You can use Ajax and PHP itself in order to update your Users about New requests. only if you want the user to be notified on runtime Ajax is something you should use
Based on your database structure I think you'll also have to set the status of your notification to be seen once the user checks the notification which will help you keep a proper count of the same.
You can setTimeout for every 15 seconds or more depending on how much your server can handle, on the Ajax request you've written.
setInterval(
function () {
fetch_new_friend_requests();
},
15000 // every 15 seconds
);