#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3

    PHP Adding Help! :: Uptime to Database


    Hello.

    I have a script and I am trying to get up time into the database. I dont know why, but when my server is offline, it still adds one. NOTE: all of the other features with offline work, and are entered correctly into the database. Any help would be greatly appreciated.

    PHP Code:
    $query mysql_query("SELECT * FROM servers") or die(mysql_error());
    $servers = array(); 
    while(
    $row mysql_fetch_assoc($query)) { 
     
    array_push($servers"{$row['serverIP']}"); 
    }

    $query mysql_query("SELECT * FROM servers") or die(mysql_error());
            while(
    $post mysql_fetch_assoc($query)){
                
    $serverActualUptime $post['serverActualUptime'];
                
    $serverPossibleUptime $post['serverPossibleUptime'];
                foreach(
    $servers as $server) {
                    
    $stats = \Minecraft\Stats::retrieve(new \Minecraft\Server($server));
                    if(
    $stats->is_online){
                        
    $serverStatus 1;
                        
    $serverMOTD $stats->motd;
                        
    $server;
                        
    $serverPOnline $stats->online_players;
                        
    $serverMPlayers $stats->max_players;
                        
    $serverVersion $stats->game_version;
                        
    $uptimeClass1 $serverActualUptime 1;
                        
    $uptimeClass2 $serverPossibleUptime 1;
                        
    $uptimePercentPart $uptimeClass1 $uptimeClass2;
                        
    $uptimePercent $uptimePercentPart 100;
                        
    $queryUpdate mysql_query("UPDATE servers SET serverStatus='$serverStatus', serverMessage='$serverMOTD', serverPlayersOnline='$serverPOnline', serverPlayersTotal='$serverMPlayers', serverVersion='$serverVersion', serverUptime='$uptimePercent', serverActualUptime='$uptimeClass1', serverPossibleUptime='$uptimeClass2' WHERE serverIP='$server'") or die(mysql_error());
                    } else {
                        
    $serverStatus 0;
                        
    $serverMOTD '?';
                        
    $server;
                        
    $serverPOnline '?';
                        
    $serverMPlayers '?';
                        
    $serverVersion '?';
                        
    $uptimeClass3 $serverActualUptime 0;
                        
    $uptimeClass4 $serverPossibleUptime 1;
                        
    $uptimePercentPart $uptimeClass3 $uptimeClass4;
                        
    $uptimePercent $uptimePercentPart 100;
                        
    $queryUpdate mysql_query("UPDATE servers SET serverStatus='$serverStatus', serverMessage='$serverMOTD', serverPlayersOnline='$serverPOnline', serverPlayersTotal='$serverMPlayers', serverVersion='$serverVersion', serverUptime='$uptimePercent', serverActualUptime='$uptimeClass3', serverPossibleUptime='$uptimeClass4' WHERE serverIP='$server'") or die(mysql_error());
                    }
                }
            } 
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    85
    Rep Power
    3
    Originally Posted by tjswebdev
    Hello.

    I have a script and I am trying to get up time into the database. I dont know why, but when my server is offline, it still adds one. NOTE: all of the other features with offline work, and are entered correctly into the database. Any help would be greatly appreciated.

    PHP Code:
    $query mysql_query("SELECT * FROM servers") or die(mysql_error());
    $servers = array(); 
    while(
    $row mysql_fetch_assoc($query)) { 
     
    array_push($servers"{$row['serverIP']}"); 
    }

    $query mysql_query("SELECT * FROM servers") or die(mysql_error());
            while(
    $post mysql_fetch_assoc($query)){
                
    $serverActualUptime $post['serverActualUptime'];
                
    $serverPossibleUptime $post['serverPossibleUptime'];
                foreach(
    $servers as $server) {
                    
    $stats = \Minecraft\Stats::retrieve(new \Minecraft\Server($server));
                    if(
    $stats->is_online){
                        
    $serverStatus 1;
                        
    $serverMOTD $stats->motd;
                        
    $server;
                        
    $serverPOnline $stats->online_players;
                        
    $serverMPlayers $stats->max_players;
                        
    $serverVersion $stats->game_version;
                        
    $uptimeClass1 $serverActualUptime 1;
                        
    $uptimeClass2 $serverPossibleUptime 1;
                        
    $uptimePercentPart $uptimeClass1 $uptimeClass2;
                        
    $uptimePercent $uptimePercentPart 100;
                        
    $queryUpdate mysql_query("UPDATE servers SET serverStatus='$serverStatus', serverMessage='$serverMOTD', serverPlayersOnline='$serverPOnline', serverPlayersTotal='$serverMPlayers', serverVersion='$serverVersion', serverUptime='$uptimePercent', serverActualUptime='$uptimeClass1', serverPossibleUptime='$uptimeClass2' WHERE serverIP='$server'") or die(mysql_error());
                    } else {
                        
    $serverStatus 0;
                        
    $serverMOTD '?';
                        
    $server;
                        
    $serverPOnline '?';
                        
    $serverMPlayers '?';
                        
    $serverVersion '?';
                        
    $uptimeClass3 $serverActualUptime 0;
                        
    $uptimeClass4 $serverPossibleUptime 1;
                        
    $uptimePercentPart $uptimeClass3 $uptimeClass4;
                        
    $uptimePercent $uptimePercentPart 100;
                        
    $queryUpdate mysql_query("UPDATE servers SET serverStatus='$serverStatus', serverMessage='$serverMOTD', serverPlayersOnline='$serverPOnline', serverPlayersTotal='$serverMPlayers', serverVersion='$serverVersion', serverUptime='$uptimePercent', serverActualUptime='$uptimeClass3', serverPossibleUptime='$uptimeClass4' WHERE serverIP='$server'") or die(mysql_error());
                    }
                }
            } 
    I think the problem lies here:
    $serverActualUptime = $post['serverActualUptime'];
    $serverPossibleUptime = $post['serverPossibleUptime'];
    as I think they should have WHERE serverIP='server'

IMN logo majestic logo threadwatch logo seochat tools logo