Zakhary Posted February 11, 2012 Share Posted February 11, 2012 Hello. I have some "finish" time in ms. (for example 14000 [14s]). Also I have others guy time like 16789ms. I have made function to math difference between times. function format_time($t) // t = miliseconds { $t1 = 16789; $t2 = 14000; $t = $t1 - $t2; $minutes = floor($t / 60000); $seconds = sprintf('%02d',floor(($t / 1000) % 60)); $ms = sprintf('%03d', $t % 1000); return $minutes . ":" . $seconds . "." . $ms; } echo "+ "; echo format_time($t); So it will be "+ 0:02.789" I still have a problem yet. I need to make this script mathing more than 1 time. I need around 20 other times to be mathed with 1st finish time and the difference to be displayed. And that's my problem. Can you give me examples or clues how can I give this script values in ms? Then, it should math every value and echo it somewhere. Can you help me in it, please? Quote Link to comment https://forums.phpfreaks.com/topic/256907-getting-data-mathing-echo-ing/ Share on other sites More sharing options...
digibucc Posted February 11, 2012 Share Posted February 11, 2012 i would store the times in a db, though here i have just supplied an array. <?php $times = array ( 16789, 14000, 15258, 13249, 12054, 19985 ); $min = min($times); function format_time($t1, $t2) // t = miliseconds { $t = $t1 - $t2; $minutes = floor($t / 60000); $seconds = sprintf('%02d',floor(($t / 1000) % 60)); $ms = sprintf('%03d', $t % 1000); return $minutes . ":" . $seconds . "." . $ms; } foreach ($times as $time){ echo '+ '. format_time($time, $min). '<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/256907-getting-data-mathing-echo-ing/#findComment-1317051 Share on other sites More sharing options...
Zakhary Posted February 11, 2012 Author Share Posted February 11, 2012 i would store the times in a db, though here i have just supplied an array. <?php $times = array ( 16789, 14000, 15258, 13249, 12054, 19985 ); $min = min($times); function format_time($t1, $t2) // t = miliseconds { $t = $t1 - $t2; $minutes = floor($t / 60000); $seconds = sprintf('%02d',floor(($t / 1000) % 60)); $ms = sprintf('%03d', $t % 1000); return $minutes . ":" . $seconds . "." . $ms; } foreach ($times as $time){ echo '+ '. format_time($time, $min). '<br>'; } ?> Would it be possible that I can enter data into this array from some kinda admin panel input? I can use MySQL ofc. Anyway this won't work as it should. I wanted it to math difference to only 1st time that I set. Not 6th to 5th, 5th to 4th and so on. Quote Link to comment https://forums.phpfreaks.com/topic/256907-getting-data-mathing-echo-ing/#findComment-1317057 Share on other sites More sharing options...
digibucc Posted February 11, 2012 Share Posted February 11, 2012 create a form that manipulates the database. it's pretty basic. as for the code - it finds the lowest time and compares every other time to that. if that's not what you want, just replace $min with whatever value you want to compare against each time is compared against min, not as you seem to think, 6->5, 5->4, etc. Quote Link to comment https://forums.phpfreaks.com/topic/256907-getting-data-mathing-echo-ing/#findComment-1317079 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.