SitePoint Sponsor

User Tag List

Results 1 to 23 of 23

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP Problems, really this hard?

    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()); 
                    } 
                } 
            } 
    Again, even though the server is offline it is still adding a one to ActualUptime, and I need it added to PossibleUptime only!

    If you can help please do so!

    Thanks,
    TJ
    Last edited by Craytor; Feb 10, 2013 at 21:13. Reason: Title fix.


Bookmarks

Posting Permissions

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