Best Way To Build A Multi-Notification System in PHP

Dwayne Charrington picture Dwayne Charrington · May 11, 2012 · Viewed 15.5k times · Source

I am currently working on a mobile app that lets you ask friends for favourites, it's a HTML5 frontend and a PHP backend. I am stuck as to what the best way is to build a notifications system, more-so the database schema than the actual code itself.

The mobile application flow is as follows:

  • A User asks for a favour
  • The user can choose to; notify all friends, notify favourite friends or notifdy closeby friends
  • Depending on what the user chose, people are notified

What is the best way to do this in PHP and MySQL? I'm not really asking for anyone to write me the PHP code, but rather map out the most ideal MySQL table and fields schema instead as that is what I am currently stuck on. Thanks in advance for your help.

Answer

Shoe picture Shoe · May 11, 2012

You can create a notification table such as:

from_user | to_user | notification | seen

and then whenever you want to notify a user you just add a record with the needed informations and set seen to 0 / false.

Then when the user reads the notification you set that parameter to 1 / true.

Example:

from_user | to_user | notification | seen
    -          -          -           -

User john notify user jeff:

from_user | to_user | notification | seen
   john      jeff       whatever..    0

User jeff read the notification:

from_user | to_user | notification | seen
   john      jeff       whatever..    1