zackcez Posted August 5, 2008 Share Posted August 5, 2008 Here's what I came up with: $percent = ("total_uptime" / ("total_uptime" + "total_downtime")) * 100; Where total total_uptime starts at 1 and total_downtime at 0...I've create a cron job to automatically add one to uptime if the server is up and if down add one to down. But I'm getting this message: Warning: Division by zero in [path]\modules\server_status\index.php on line 262 If anyone could either correct my math or help me find a different way to do this I'd very much appreciate it. PS: The total_uptime and total_downtime are rows in my mysql database. Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/ Share on other sites More sharing options...
trq Posted August 5, 2008 Share Posted August 5, 2008 Look at your code. "total_uptime" and "total_downtime" are literal strings. Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608182 Share on other sites More sharing options...
zackcez Posted August 5, 2008 Author Share Posted August 5, 2008 But that doesn't solve my problem :s Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608218 Share on other sites More sharing options...
trq Posted August 5, 2008 Share Posted August 5, 2008 Um, yes it does. Your trying to devide two strings. Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608221 Share on other sites More sharing options...
zackcez Posted August 5, 2008 Author Share Posted August 5, 2008 No it's still not working :s, here's my complete code with the values that are in my db: $percent = total_uptime / (total_uptime + total_downtime) * 100; //1 / by 1+0 = 1 * 100 = 100 Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608251 Share on other sites More sharing options...
zackcez Posted August 5, 2008 Author Share Posted August 5, 2008 Also, here's the query $query = $db->query('SELECT * FROM server_status ORDER BY up && ".$percent." DESC'); Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608257 Share on other sites More sharing options...
cooldude832 Posted August 5, 2008 Share Posted August 5, 2008 now you are trying to divide a constant by the sum of 2 constants which in turn gives you another constant Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608267 Share on other sites More sharing options...
zackcez Posted August 5, 2008 Author Share Posted August 5, 2008 Okay lets then say this is my code again: $percent = (total_uptime / (total_uptime + total_downtime)) * 100; Any ideas then lol? Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608284 Share on other sites More sharing options...
trq Posted August 5, 2008 Share Posted August 5, 2008 I don't think your seeing the problem. total_uptime and total_downtime are not numbers! Maybe if you where using the variables $total_uptime and $total_downtime that you defined somewhere previously but at the moment there just strings when within quotes or undefined constants when outside of them. Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-608304 Share on other sites More sharing options...
947740 Posted August 15, 2008 Share Posted August 15, 2008 Oh, and if you do use constants, you normally capitalize them. So: TOTAL_UPTIME and TOTAL_DOWNTIME would be the 'correct' way to define them. Quote Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-617590 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.