...

View Full Version : Most users online, problem



PeterJS
06-06-2004, 01:54 PM
I made a PHP code to record the most users online ever, and out put it to a page with the date.

How it works:

We use a remotely host free forum from ProBoards, so we have had to work out our own way to get the data to the php script. It works by having a hidden field, when the page loads it stores the amount of people online in the field and then submits the form to a hidden iframe. Works well, but for some reason, one moment it tells me that the most online was 38, then I notice it's dropped down to a lower number.

Before the value get's put into the MySQL database it checks to see if the new value is lower then the old value that's in the database, I don't understand how it could still enter a lower value into the database.

i'm just using something like........

$result = mysql_query("SELECT * FROM mostonline LIMIT 0 , 1");

while($row = mysql_fetch_object($result)){
$oldVal = $row->online;
$oldDate = $row->date;
}

if($total < $oldVal){

code

}


Hope someone can offer some help

Thanks

fimi
06-06-2004, 11:10 PM
Before the value get's put into the MySQL database it checks to see if the new value is lower then the old value that's in the database, I don't understand how it could still enter a lower value into the database.

if($total < $oldVal){

code

}

I'm thinking the $total variable has the new value of users that are logged in and the "code" is the code where you insert the new online user count into the database!
Don't worry put the other code because we're not going to hack or steal your idea; we can't help you that much if you take the code off.

You were comparing if the $total is lower than the value of $oldVal. That executes when the $total is smaller so that's why it allways inserted the lower value.

this should work:

if($total > $oldVal){

//code to enter the new value into the database.

}

PeterJS
06-07-2004, 02:09 AM
Hi,

I tried it that way as well, but there is still a problem....


$total = $_POST['total'];

echo "document.write('<iframe width=\"0\" height=\"0\" id=\"frame\" name=\"frame\"></iframe>')\n";
echo "document.write('<form action=\"****/store.php\" method=\"post\" enctype6=\"multipart/form-data\" name=\"amount\" target=\"frame\" id=\"amount\">')\n";
echo "document.write('<input name=\"total\" type=\"hidden\" id=\"total\" value=\"0\"></form>')\n\n";

echo "var GetID = document.getElementById\n";
echo "var GetTag = document.getElementsByTagName\n\n";

echo "function getTotal(){\n";
echo "\tvar onCell = GetTag(\"td\")\n";
echo "\tfor(c=0;c<onCell.length;c++){\n";
echo "\t\twith(onCell[c]){\n";
echo "\t\t\tif(vAlign==\"top\" && align==\"left\" && innerHTML.match(/>(\d+).+\s(\d+)\s\w{6}/i)){\n";
echo "\t\t\t\tfirstChild.innerHTML += \"<br /><br /><center>Most users online ever was ";

$result = mysql_query("SELECT * FROM mostonline LIMIT 0 , 1");

while($row = mysql_fetch_object($result)){
$oldVal = $row->online;
$oldDate = $row->date;
}

if($total > $oldVal){

$timestamp = time();

$query = "UPDATE mostonline
SET online='$total',date='$timestamp'
WHERE id='0'";

mysql_query($query);

echo "<b>".$total."</b> on <b>".gmdate('F jS, Y',$timestamp)."</b>";

} else {
echo "<b>".$oldVal."</b> on <b>".gmdate('F jS, Y',$oldDate)."</b>";
}

echo "</center>\"\n";
echo "\t\t\t\treturn((Math.floor(RegExp.$1) + Math.floor(RegExp.$2)))\n";
echo "\t\t\t}\n";
echo "\t\t}\n";
echo "\t}\n";
echo "}\n\n";

echo "if(location.href.match(/ssdesigns/i)){\n";
echo "\tif(location.href.match(/(=log|.com\/\w+.cgi[\?]*$|^.{6}\/\w*.p\w{8}\d*.com\/$)/i)){\n";
echo "\t\tGetID(\"total\").value = Math.floor(getTotal())\n";
echo "\t\twindow.onload = function(){ GetID(\"amount\").submit(); return false }\n";
echo "\t}\n";
echo "}\n\n";

exit;

mysql_close($link);

fimi
06-07-2004, 02:49 AM
"a problem", is it the same problem or different?

echo the $oldVal and $total variables to see what value do you get. maybe the $oldVal is emtpy!

ps. there is no while loop because there is only one result!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum