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. 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. 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 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. 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 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'); 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 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? 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. 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. Link to comment https://forums.phpfreaks.com/topic/118185-solved-percent-of-uptime/#findComment-617590 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.