I need to be able to monitor new records in a table (in a live way).
The easiest way I figured to do that would be to run a loop and when the total number of records in a table changes, then proceed with whatever else the page needs to do, then, just start over.
The way I went about doing this is:
This pretty much works, but i'm nervous about this page going through a possibly infinite loop. Is this way dangerous or stupid? And if so, by what other means would be better to handle this?
I'm not familiar with AJAX to know a way to do it that way.
The easiest way I figured to do that would be to run a loop and when the total number of records in a table changes, then proceed with whatever else the page needs to do, then, just start over.
The way I went about doing this is:
Code:
$sessionid = $_GET['session'];
mysql_select_db($database, $connection);
$query_getsession = "SELECT * FROM dialog WHERE `session` = '".$sessionid."'";
$getsession = mysql_query($query_getsession, $connection) or die(mysql_error());
$totalRows_getsession = mysql_num_rows($getsession);
$query_checksession = "SELECT * FROM dialog WHERE `session` = '".$sessionid."'";
for($i=0;$i<=3;$i++){
mysql_select_db($database, $connection);
$checksession = mysql_query($query_checksession, $connection) or die(mysql_error());
$totalRows_checksession = mysql_num_rows($checksession);
if($totalRows_checksession > $totalRows_getsession){
$i = 5;
} else {
$i = 1;
}
}
This pretty much works, but i'm nervous about this page going through a possibly infinite loop. Is this way dangerous or stupid? And if so, by what other means would be better to handle this?
I'm not familiar with AJAX to know a way to do it that way.