I've been working on a chat module as a little side project of mine, and i'm having a bit of a problem.
In order to show the 'active users', I've set up a page inside of a frame (refreshing every 5 seconds) that gets the timestamp of the most recent posts, then displays the username of the ones who have posted in the last 5 minutes (300 seconds).
On line 43 (while ($colorarray[$y] != NULL){) and (but more often) line 56 ( if (in_array($current, $used) != TRUE) { ), it gives me the fatal timeout error.
I was wondering if anyone knew why, or if anyone knew a way to optimize the code so it didnt do that.
Thanks,
Fariel
<?
include 'chatconnect.php';
$fiveminutesago = time() - 300;
$query="SELECT * FROM message WHERE usertime > $fiveminutesago";
$result=mysql_query($query);
$num=mysql_numrows($result);
if ($num==0) {
echo "No one is online!?";
} else {
$i=0;
while ($i < $num) {
$user=mysql_result($result,$i,"user");
$usertime=mysql_result($result,$i,"usertime");
$color=mysql_result($result,$i,"color");
include 'messagecolor.php';
$userarray[$i] = $user;
$colorarray[$i] = $color;
$i++;
}
}
$g = 1;
$y=0;
while ($colorarray[$y] != NULL){
if ($g == 1) {
echo "<div id=\"message\" style=\"background-color:".$colorarray[$y]."\" width=\"100%\">".$userarray[$y]."</div>";
$used[$y] = $userarray[$y].$colorarray[$y];
$g++;
$y++;
$current = $userarray[$y].$colorarray[$y];
}
if (in_array($current, $used)) {
}else{
echo "<div id=\"message\" style=\"background-color:".$colorarray[$y]."\" width=\"100%\">".$userarray[$y]."</div>";
$current = $userarray[$next].$colorarray[$next];
$used[$y] = $userarray[$y].$colorarray[$y];
$y++;
}
}
?>