Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2002
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Most users online, problem

    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

  • #2
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PeterJS
    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:
    PHP Code:
    if($total >  $oldVal){

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


    |Tip: Use a template engine to separate your PHP code from HTML [Smarty]
    |Helpful: Follow the forum rules and posting guidelines, they apply to all of us [Rules] - [Posting Guidelines]
    |Me: [MSN][Y!][AIM][@] - fimi

  • #3
    New Coder
    Join Date
    Dec 2002
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

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

    PHP Code:
    $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); 

  • #4
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "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!
    |Tip: Use a template engine to separate your PHP code from HTML [Smarty]
    |Helpful: Follow the forum rules and posting guidelines, they apply to all of us [Rules] - [Posting Guidelines]
    |Me: [MSN][Y!][AIM][@] - fimi


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •