Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-11-2013, 03:09 AM   PM User | #1
Craytor
New to the CF scene

 
Join Date: Feb 2013
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Craytor is an unknown quantity at this point
MySQL Error - Is it 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.

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
Craytor is offline   Reply With Quote
Old 02-11-2013, 11:40 AM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Quote:
Originally Posted by Craytor View Post
Again, even though the server is offline it is still adding a one to ActualUptime, and I need it added to PossibleUptime only!
Well that tells you then that there is something wrong here:
if($stats->is_online){

Your code will not add 1 to the uptime if that line evaluates as false but if it evaluates as true, it will add one.

Whatever that line of code is doing, it's not reliable.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:30 AM.


Advertisement
Log in to turn off these ads.