How do alerts work?

Discussion in 'Webmastering & Programming' started by pothb, May 8, 2016.

  1. pothb

    pothb [H]ardness Supreme

    Messages:
    4,997
    Joined:
    Mar 24, 2007
    And by alerts, I'm meaning like the ones this forum uses, where it automatically sends out notce to the user that there was an update to your subscribed posts/thread. Is it an sql trigger?

    I only really have rudimentary knowledge of SQL, took a class a (VERY) long while ago and am sort of looking back into it. Triggers weren't even mentioned in the class I took, but in my web searches, this seemed like the best possibility.
     
  2. CEpeep

    CEpeep [H]ardness Supreme

    Messages:
    6,061
    Joined:
    Oct 23, 2004
    The alerts are AJAX, Javascript that runs in your browser all the time while you have [H] open that constantly asks the server if there are any alerts for you without you having to refresh the page.

    How they are handed on the backend (PHP talking to the SQL database) varies widely, but depending on the type of alerts you are generating and the structure of your DB, a trigger could be a fine way of implementing something like this.
     
  3. pothb

    pothb [H]ardness Supreme

    Messages:
    4,997
    Joined:
    Mar 24, 2007
    I see... I was definitely hoping for it to not be a constant request type thing. Hopefully it could be a one way street with triggers only.

    Regardless, thanks for the reply.
     
  4. CEpeep

    CEpeep [H]ardness Supreme

    Messages:
    6,061
    Joined:
    Oct 23, 2004
    There's no way in the browser (aside from the new HTML5 Alerts supported by some browsers) to push information/alerts back to the user without some sort of listener JS running in the browser. This is why AJAX was such a revolution when it came into vogue. An SQL trigger by itself cannot update content in the user's browser without the user choosing to refresh the page. That's what the JS is doing: listening constantly for changes and then applying them in realtime. This is outside of the scope of SQL triggers.
     
  5. pothb

    pothb [H]ardness Supreme

    Messages:
    4,997
    Joined:
    Mar 24, 2007
    Well, I'm thinking of more for android programming, with interactions with a database, the alerts mention was more for reference on what I was talking about because I'm sure I wouldn't be able to describe it well otherwise.
     
  6. CEpeep

    CEpeep [H]ardness Supreme

    Messages:
    6,061
    Joined:
    Oct 23, 2004
    You have many more options on Android, since there is a while infrastructure set up for push alerts as pat of the OS. The function that JS serves in the browser is being handled natively in the OS which gives you many more options. It could be possible to fire off a push notification to an Android user with only a stored procedure/trigger, but It's not something I've worked on.
     
  7. pothb

    pothb [H]ardness Supreme

    Messages:
    4,997
    Joined:
    Mar 24, 2007
    Actually... now that you mention it, I never reall considered Android side of it since I'm thinking of a update after an off device database is updated, but I guess it's possible to send for the update and send an alert to the other phones from the phone as well... probably a bit a messy but it might work.
     
Tags: