Jump to content

[SOLVED] calculating correct time


Crew-Portal

Recommended Posts

Lets start off by giving you my code (Well the important sections of it!):

<?php
/**/	# Total Time
/**/	$query = "SELECT sum(hours) FROM flights ".$condition;
/**/	$result=mysql_query($query);
/**/	$blcktime = number_format(mysql_result($result,0));	
/**/	$query = "SELECT sum(minutes) FROM flights ".$condition;
/**/	$result=mysql_query($query);
/**/	$blckmins = number_format(mysql_result($result,0));
echo "$blcktime:$blckmins";	
?>

Okay this part works. Like if there is an entry that has 20 hours in hours table and 50 minutes in minute table it displays 20:50, but my problem is if there are more than one record (Which there will be) if the previous was still true and another record had 1:30 the total would be 21:80 but this of course is not correct addition of time. And this is not a 24 hour clock it simply displays the time someones been in a game so it can go lke 300:56 too.

 

Now how would I get it so if the $minutes were greater than 60 and divisible by 60 it would add the correct numbers to the hours like $hours = $hours + $times_divisible; or something like that! I am okay with if..else..elseif statements but that would take forever to write. thats why I need a looping sttatement but I havent got a clue how to write it. If anyon could help I would greatly appreciate it! Like High five Appreciation! ;) Thanx, and sorry but in my PHP book I never did understand how to loop

Link to comment
https://forums.phpfreaks.com/topic/75606-solved-calculating-correct-time/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.