Real-time database monitor

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Justin Voelker

    Real-time database monitor

    I have built a php website with a messaging system where users of a
    website can send messages to each other and they will appear in the
    other users inbox for viewing next time they log in. In a bar at the
    top of the page it says "Inbox (0)" if they have no new messages and,
    yup, you guessed it "Inbox (2)" if they have two waiting messages. If
    someone sends them a message while they are sitting on some page of
    the website I would like the counter to increase. Each time someone
    sends a message it creates a new record in a single table in the
    database. What I am looking for is a way to monitor that database and
    find any records with "msg_to" equal to the user id of the person
    logged in and "msg_unread " equal to '1.' Right now the mysql query
    runs each time a page is loaded so they would be notified then but I
    would like it to somehow update the inbox number while they sit on a
    page. Does anyone have any ideas? I was told in the comp.lang.php
    group that AJAX might be able to help and that I should check this
    group. Thank you in advance for your help!
  • Laser Lips

    #2
    Re: Real-time database monitor

    Justin, this is really simple to do.

    Write a PHP script (e.g getMailCount.ph p ) and in it put your code
    which gets the count of new messages for the user, where user id the
    value you pass to this script, probably using $_REQUEST["UserID"] or
    somthing similar.

    This PHP script needs to echo the number of NEW messages, so at the
    end of this script say somthing like 'echo $numberOfNewMes sages;'

    You will need to call this script with the user id in the URL so
    somthing like blar/blar/getMailCount.ph p?UserID=234

    Using Ajax, you call this script. You get the return value and you
    set the contents of the DIV containing the 'new mail number' to the
    value that the script returns.

    Graham

    Comment

    Working...