MR-4O4
MR-4O4

Reputation: 321

User notification/alert system with ajax php mysql

I have been working on a project where I need to show a notification to a user whenever some activity happens under his profile(like if someone comments on his photo).

I am planning made it using PHP and mysql with ajax(for asynchronous requests) .

 Table 'alerts':

   Id(PK)     by_id(FK)   notification                   is_seen
    10          02        max commented on your photo.   true
    20          45        john replied to your comment.  true
    30          65        jack liked your photo .        true
    40          41        jill poked you.                false

What I am doing is if a loggedin user(say max) comments on another user(say ben's) pic, then I am first forming a notification("max commented on your photo"), saving it to db like above, and then showing his notification to the other user(ben) via ajax which refreshes every 5 seconds.

I wanted to ask what should be my database table structure for such notifications?

Is it the suitable way of making such system in php?

Should I save the entire notification in my db (like above) ?

Or is their any other method better method of doing it?

Note: I don't want to use websockets as I am not expecting much traffic in future(it's for a school site).

Thanks in advance.

Upvotes: 0

Views: 1156

Answers (1)

Theodis Butler
Theodis Butler

Reputation: 146

I would remove the names (i.e. jack and jill) in the notification column and just add the event (i.e. commented on your photo).

I would then create a separate column for the userid (FK) of the person who performed the action along with a column for the userid of the receiver of the action.

Instead of true/false use BOOLEAN datatype and store as 1 or 0.

Upvotes: 1

Related Questions