Multiple Notifications SetInterval

There’s two approaches you may want to use here, depending on the notification behavior desired:

To notify each user any time there are new notifications:

  1. You need to make sure your sql query returns the notifications in a sorted order (preferably with descending data timestamps) and includes a unique identifier/primary ID [PID] for the rows of data.
  2. In your AJAX function, if the local storage value is set, it can be used to compare/traverse the returned dataset and ignore all records from that point on in the counting process (optionally you could truncate the data using that value, or update your sql query to accept it as an argument and search/filter for only those records that are newer).
  3. After determining how many new notifications there are, store the PID of the first record (most recent record) in the returned dataset back to local storage for subsequent calls.

To notify only one admin user:

  1. Add a boolean flag field on the database for each row which has already been acknowledged in the notification process.
  2. Use this to filter the query used for the AJAX call.
  3. Update the records returned in the AJAX call by setting the field.

You could add more boolean fields for multiple users/user types, but it would cause a lot of database bloat.