Re: Real-time database monitor
- From: Justin Voelker <justin.voelker@xxxxxxxxx>
- Date: Thu, 8 May 2008 06:14:09 -0700 (PDT)
On May 8, 8:15 am, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m...@xxxxxxxxxxxxxxxx> wrote:
Justin Voelker schreef:
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!
Hi,
I saw you posting in comp.lang.php.
Yes, XMLHttpObject (AJAX) is a good solution for this.
Be aware however that this only works for visitors with JavaScript
enabled. While this is the vast majority, it isn't 100%.
(I keep hearing different percentages, but most are over 90%)
If you decide to do it with AJAX, then this is a good place to start:http://www.w3schools.com/ajaxbut many other resources exist.
If you want it to work for the world at large (= also for those without
JavaScript), you might want to use a frame or an IFrame.
In this IFrame you place your inbox thingy.
You can use META tags in the HTML document to order it to refresh every
X seconds.
Using AJAX will look smoother than using a refreshing IFrame, because
the page in the IFRame must refresh every X seconds, while AJAX will
only update some content on your page (No IFrames needed).
Hope that helps.
Regards,
Erwin Moller
Thank you for the great help! Because of the nature of the website
and the other various tools available to the users, they must have
javascript enabled to even view the site (the entire site is based
around a good map which needs js). I looked at the w3schools ajax and
I think I understand their examples bt I do have one more question. I
have a limited knowledge of javscript (just enough to be dangerous).
I see in the w3schools examples they reply on the "onchange" event of
a dropdown. What would I need to do since I can't user an "onchange"
event or anything else that requires user interaction? My only
thought is something that executes the command every X seconds, but
wouldn't that cause a lot of server load if there are lots of users?
If this is what I need to do, what code would I use. Thank you again
for the wonderful help!
.
- Follow-Ups:
- Re: Real-time database monitor
- From: Erwin Moller
- Re: Real-time database monitor
- References:
- Real-time database monitor
- From: Justin Voelker
- Re: Real-time database monitor
- From: Erwin Moller
- Real-time database monitor
- Prev by Date: 'this' and <A HREF="...">
- Next by Date: Re: Why do this? <SCRIPT TYPE="text/javascript"
- Previous by thread: Re: Real-time database monitor
- Next by thread: Re: Real-time database monitor
- Index(es):
Relevant Pages
|