473,387 Members | 1,700 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Looking for a solution to have php refresh when new data hits database

348 100+
Hi everyone,

I am looking for a php and maybe javascript solution that will show a particular php page when there is new data entered into a database table.

So when a field in a table has new data inserted, maybe a javascript alert or something else could notify the user that there is new data inserted. Realtime I guess is what I am talking about. I wouldn't even know how to go about implementing this without a UNIX cron job. Cron is not really a solution because it should be in realtime.

Can someone maybe tell me if this is at all possible?

Thanks,

Frank
Aug 19 '07 #1
18 2271
pbmods
5,821 Expert 4TB
Heya, Frank.

The simplest way I can think of to do this would be to log the date when the User checks for new entries. Then, all you have to do is display all entries whose date is after the last check date.
Aug 20 '07 #2
fjm
348 100+
Heya, Frank.

The simplest way I can think of to do this would be to log the date when the User checks for new entries. Then, all you have to do is display all entries whose date is after the last check date.
Hey Pbmods!

Thanks for the reply. Maybe I wasn't clear before but what would need to happen would be when user1 is working on any page of the website and another (completely seperate user-not known to user1) drops info to the db, is it possible for a javascript alert to alert user1 of the new data? The whole point would be so that user 1 *shouldn't have to* check for updates.

In other words, so that user1 doesn't have to go back to a certain screen and check for new data. I'm sorry if I am not clear.

Thanks again,

Frank
Aug 20 '07 #3
pbmods
5,821 Expert 4TB
Heya, Frank.

So what you're saying is that you would like to do a periodic check via AJAX to see if the database has been modified while the User is making changes. Is this correct?
Aug 20 '07 #4
fjm
348 100+
Heya, Frank.

So what you're saying is that you would like to do a periodic check via AJAX to see if the database has been modified while the User is making changes. Is this correct?
Hey Pbmods..

Well.. kind of... I guess we could put an example likr this.

Say that user1 (the person that needs to know about the newly inserted data). Say this person is not even on his computer but talking on the telephone.

While this telephone conversation is going on, User2 dumps info into the db at this point but user1 has no idea because he is still on the telephone.

User1 *could* however go to that page that would tell him that new data has been inserted but I need a solution that will notify user1. Be it a bell, whistle, hammer on the head, something :) Something to alert user 1 that new data is there.

Thanks,

Frank
Aug 20 '07 #5
pbmods
5,821 Expert 4TB
Heya, Frank.

Ok. So you want the User to get some kind of a notification outside of the context of your website. Perhaps you want your site to send out an email?

The easy way to do this would be to add your mailer to the end of any script that modifies the database.
Aug 20 '07 #6
ronnil
134 Expert 100+
Hi Frank

I'd have to go with pbmods. Use Ajax (that's what the others use). Every 10 seconds or so you send a request to a specific page, if the response is not empty, new info must have been dropped.

This works through Javascript and therefore makes it very easy notifiyng the user with an alert box or a pop-up (or whatever)

may i suggest you take a look at http://www.w3schools.com/ajax/default.asp
Aug 20 '07 #7
jx2
228 100+
well as the guys above said there is no real solution (i wish there was)
but you can work around this limitation with ajax - well its ok but thats not really solution if you want it to be done in real tiime - ajax can send requests every second or even more often then that (for me one second is too much)
and if you have many users server will have to deal with many requests - its very limiting

my idea (wich i am trying right now for my litle game)is to use infinite loop in php
[php]<?php
while(1){
checkDB();
sleep(1);
}
function checkDB(){

$file = file('d.txt');
if($file[0]){
echo $file[0];
exit;
}
}[/php]

yeah i know its still have limitation maximum execution time :-)

well if you use ajax togheter with it your and up with ajax requesting your server every $MAX_EXECUTION_TIME (usualy 30sec) and you will gain really REAL time control

i should copyright this technology ;-) its working wonderfully

regards
jx2
Aug 20 '07 #8
fjm
348 100+
Hi Frank

I'd have to go with pbmods. Use Ajax (that's what the others use). Every 10 seconds or so you send a request to a specific page, if the response is not empty, new info must have been dropped.

This works through Javascript and therefore makes it very easy notifiyng the user with an alert box or a pop-up (or whatever)

may i suggest you take a look at http://www.w3schools.com/ajax/default.asp
Hi Ronnil,

Thanks for the reply. Honestly, I wish I had the time to learn AJAX but it isn't an option for me. I can however look aroind and see if I can find someone that has already created something like this.

What do you guys think about the infinite loop provided by jx2? Seems easy.. :) Very very tempting....
Aug 20 '07 #9
fjm
348 100+
well as the guys above said there is no real solution (i wish there was)
but you can work around this limitation with ajax - well its ok but thats not really solution if you want it to be done in real tiime - ajax can send requests every second or even more often then that (for me one second is too much)
and if you have many users server will have to deal with many requests - its very limiting

my idea (wich i am trying right now for my litle game)is to use infinite loop in php
[php]<?php
while(1){
checkDB();
sleep(1);
}
function checkDB(){

$file = file('d.txt');
if($file[0]){
echo $file[0];
exit;
}
}[/php]

yeah i know its still have limitation maximum execution time :-)

well if you use ajax togheter with it your and up with ajax requesting your server every $MAX_EXECUTION_TIME (usualy 30sec) and you will gain really REAL time control

i should copyright this technology ;-) its working wonderfully

regards
jx2
Jx2,

Thanks for the snippet.. I never thought about using an infinate loop. :) My solution doesn't have to provide true "real time" but has to provide something that would alert or notify the computer user when there has been new data inserted into the database within a reasonable amount of time. Say between 1 and 2 minutes.

Thanks!

Frank
Aug 20 '07 #10
fjm
348 100+
Heya, Frank.

Ok. So you want the User to get some kind of a notification outside of the context of your website. Perhaps you want your site to send out an email?

The easy way to do this would be to add your mailer to the end of any script that modifies the database.
Hey Pbmods...

When I initially read this reply, it didn't make sense to me but now a little lightbulb went on..... Are you saying to *simply* put at the end of my php script, something that would, say, in javascript, pop up on the screen after the data has been inserted??????

Beautiful man!!!!!!!!!!!!!!!!!!! You guys rock! BTW: I'm sooooo embarrased... :blush:
Aug 20 '07 #11
pbmods
5,821 Expert 4TB
Heya, Frank.

We aim to please.

Good luck with your project, and as always, if you ever need anything, post back anytime :)
Aug 20 '07 #12
fjm
348 100+
Heya, Frank.

We aim to please.

Good luck with your project, and as always, if you ever need anything, post back anytime :)
Hey Pbmods.. Thanks again and you can bet I will be back. ;)
Aug 20 '07 #13
ronnil
134 Expert 100+
Jx2,

Thanks for the snippet.. I never thought about using an infinate loop. :) My solution doesn't have to provide true "real time" but has to provide something that would alert or notify the computer user when there has been new data inserted into the database within a reasonable amount of time. Say between 1 and 2 minutes.

Thanks!

Frank
Yep that is infact a pretty good solution. Haven't needed this type of thing for an instant messenger or anything, but when i do.... hope you don't mind me borrowing your idea ;)
Aug 21 '07 #14
fjm
348 100+
Yep that is infact a pretty good solution. Haven't needed this type of thing for an instant messenger or anything, but when i do.... hope you don't mind me borrowing your idea ;)
Hey Ronnil,

I liked that idea too. I also liked Pbmods idea as well. After all it seemed so easy. I am thinking about how to implement Pbmods javascript solution into my project but it is dawning on me that it is not going to be possible.

Consider this...

My server is a UNIX box that is off site. The person using the php program is on a windows machine; we will call him User1. When another user (User2) inserts data to the database how would it be possible to use javascript which we all know is a client side language to alert User1 on a completely different machine?

I really don't care one way or the other as long as I can come up with a solution. If javascript is not possible, I am wondering how I could implement an infinate loop as Jx2 suggested.
Aug 21 '07 #15
pbmods
5,821 Expert 4TB
Heya, Frank.

Try a hybrid.
  • When the User updates the database, log the timestamp.
  • While a User is logged in, check via AJAX once every X seconds to see if this timestamp has changed and alert the User if it has. Update a different timestamp every time the AJAX call connects so that you know that the User has been notified.
  • Once per X hours, send a notification email to every user where their check-for-updates timestamp is less that their database-was-modified timestamp.
  • You can create a separate table that lists the modification timestamps for each table if you want to be able to determine which tables were modified when sending emails / AJAX results.
Aug 21 '07 #16
fjm
348 100+
Heya, Frank.

Try a hybrid.
  • When the User updates the database, log the timestamp.
  • While a User is logged in, check via AJAX once every X seconds to see if this timestamp has changed and alert the User if it has. Update a different timestamp every time the AJAX call connects so that you know that the User has been notified.
  • Once per X hours, send a notification email to every user where their check-for-updates timestamp is less that their database-was-modified timestamp.
  • You can create a separate table that lists the modification timestamps for each table if you want to be able to determine which tables were modified when sending emails / AJAX results.
Hey Pbmods..

Timestamps.. Of course. I can have AJAX look for a change then alert. Not quite sure how to do that yet with AJAX. Is there a complete AJAX script that you know of that I can use or is this something that I would have to write? I do not know AJAX at all.

Thanks,

Frank
Aug 21 '07 #17
pbmods
5,821 Expert 4TB
Heya, Frank.

On the PHP side, simply echo strtotime({date from db}); Then on the javascript side, you can compare the last timestamp with the new one; they'll both be unsigned integers (hopefully).
Aug 21 '07 #18
jx2
228 100+
Hey Pbmods..

Timestamps.. Of course. I can have AJAX look for a change then alert. Not quite sure how to do that yet with AJAX. Is there a complete AJAX script that you know of that I can use or is this something that I would have to write? I do not know AJAX at all.

Thanks,

Frank
hey
you should look here

in your case that very easy you send "ajax" request to serwer - if there is new record php send this record(or just worning) back to browser if there is no new records then it send empty string

i woud have <span id='newrecord'> on my page</span> and whatever you going to send back it can be displayed there with javascript

regars jx2
Aug 21 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: toylet | last post by:
Any website that has discussion about programming a one-to-many input form (like an invoice) using php and mysql? I want to see how professional codes it, and handle issues related to the refresh...
6
by: Mark Feller | last post by:
What are best practices to check to see if a .php script is called for the first time versus a user hitting a refresh button on their browser? I am playing around with a PHP front-end to a...
22
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
3
by: Dave | last post by:
Hey, I'm running a localhost web server...W2K with IIS 5.0, and I'm trying to use ASP/ADO to access my Access database. When I first load the page, everything works, but if i hit refresh (F5 or...
1
by: Johann Blake | last post by:
I am looking for a good solution on how to implement data access in an application so that there is a clean separation between the data access layer, the business layer and the GUI layer. I am...
7
by: Robin | last post by:
In a current .Net solution (using VB.Net) has a 3 tier architecture of Web interface, Data Access Layer and Database. How do I implement business logic and class layers into this solution?
2
by: Robert | last post by:
I am trying to give the user dynamic search capabilities to select almost any record in the database from criteria they select. Everything seems to work except when I open the display form to...
0
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.