Hello all,
I'm new here, but you all seem to be very helpful after viewing a lot of threads. I'm after a solid, yet light, way to watch a MySQL table with PHP for updates. I'm using it for a homemade PHP chat system I am working on. So far the solution I've come up with, works, but not as well as I believe it could. Here's how I have it setup.
The first page counts the number of entries in my chat database, then sleeps, loads the second page and compares the number of entries to the first number of entries. If there are more than previously, it targets a frame to reload the "Chat Display" page. The sleep function doesn't really seem to be what I want, and I'm sure there is a smarter way to do this. Any help would be greatly appreciated.
-Sys
chat_checker1.php:
<?php
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM $chat";
$result=mysql_query($query);
$num=mysql_numrows($result);
sleep(2);
echo "<meta http-equiv=refresh content=0;URL=chat_checker2.php?count=$num>";
?>
chat_checker2.php:
<?php
$count=$_GET['count'];
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM $chat";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num > $count) {
echo "<script language=javascript>";
echo "top.top.location.href = 'chat_view.php'";
echo "</script>";
echo "<meta http-equiv=refresh content=0;URL=chat_checker1.php>";
}
else {
echo "<meta http-equiv=refresh content=0;URL=chat_checker1.php>"; }
?>