0

thanks for giving your time .

I have a webpage which fetch "Notifications " created by admin to users from a MYSQL database using PHP script. Now i want to that if Admin create a new notification It should be Dynamically added to user page.

just like Facebook , when a user is logged in and his friend post something , at that instant i can see a Notification of new post Without reloading the page.

Akash Varde
  • 83
  • 1
  • 11
  • This is very broad question and there are many articles/tutorials about such implementations. Anyway, in a short words, you probably should look for websockets, but PHP is not the best language for that, but still, it's possible. – Jakub Matczak Jun 21 '16 at 06:48
  • Guys , sorry to mention late , i don't want to include any google API or link references. – Akash Varde Jun 21 '16 at 06:48

2 Answers2

4

The 2 options you got is either to use ajax or websockets to make this.

Ajax

Create a script "notification.php" that you call with ajax and it will either return the amount of notifications where 0 will mean nothing, anything above 0 will add the number next to the notification icon.

http://blog.teamtreehouse.com/beginners-guide-to-ajax-development-with-php

Websockets

Run javascript websocket towards a PHP websocket server that will send a message to the client with the amount of notifications in real-time. Same logic as with ajax.

http://code.tutsplus.com/tutorials/start-using-html5-websockets-today--net-13270

Diffrence

Ajax you can have a interval and check every 15/30sec for new notifications, when websocket will be instant.

Fyllekanin
  • 274
  • 1
  • 12
  • Sorry friend , The reference u given about AJAX is not working for me , in that we have to click a "Fetch more button" where as in my scene , new notification should be appeared **Automatically.** For this i think we should use Ajax which have a timer of some seconds which will notify new notification . – Akash Varde Jun 21 '16 at 07:04
  • That's just a reference how to use ajax, you can build a function that makes the AJAX call and get the response then have a interval that repeat this function every for example 15sec. http://stackoverflow.com/questions/5052543/how-to-fire-ajax-request-periodically – Fyllekanin Jun 21 '16 at 07:10
  • the term is long-polling.. –  Jun 21 '16 at 07:17
  • Can't believe I haven't heard about WebSockets till today! +1 – Ikhlak S. Jun 21 '16 at 08:42
1

There is manu many ways to do this one of them might be this .Simply define some user groups and send these notification to them,when you want to check notifications check group notifications too, in fact you will insert only one row to the database but all of users in its group can see it. If your problem is about how to fetch these notifications you can define a JavaScript interval and check for new notifications from server with ajax.

Javad
  • 63
  • 1
  • 9