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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.