-1

I'm not a programator, I'm not a student. I just play with HTML, CSS and PHP for my own pleasure. For now, I try to make a webpage for my running. I would like to calculate my PACE (mm:ss/KM) from my DISTANCE (KM) and running time (mm:ss) or better (hh:mm:ss).

Can anyone help to PHP begginer? I have no idea how to code it.

<?php
$distance="6.03";
$hours="00";
$minutes="34";
$seconds="13";

$time=($hours*3600)+($minutes*60)+$seconds;
$speed=($time/$distance)/60;
$speed1=date('i:s', $speed);
?>

$distance is 6.03 km
$time gives me rum time in seconds (2053 seconds)
$speed gives mi number 5.67440574903
$speed1 gives me 00:05

Martin
  • 65
  • 1
  • 8
  • it's just basic maths, think about it logically.. `$speed = $km / $time` – treyBake May 18 '17 at 13:02
  • Basic maths ... so I do it somewhere wrong ... – Martin May 18 '17 at 14:54
  • I have no idea if you did it somewhere wrong you've posted no code friend :) – treyBake May 18 '17 at 14:54
  • Basic maths ... so I do it somewhere wrong ... $distance="6.03"; $hours="00"; $minutes="34"; $seconds="13"; $time=($hours*3600)+($minutes*60)+$seconds; $speed=($time/$distance)/60; I have distance in KM, time in SECONDS and speed gives me 5.67440574903 minutes if am I right. Can somebody help me convert that number to mm:ss? I try date('i:s', $speed); but it gives to me 00:05 – Martin May 18 '17 at 15:04
  • update your question with the code - that's unreadable haha – treyBake May 18 '17 at 15:04
  • First time here, can you help me, le me know how to write a code to this comment please? – Martin May 18 '17 at 15:09
  • use backticks to format - but I'd still recommend putting it in the post rather than the comment – treyBake May 18 '17 at 15:10
  • What is `time1` if you don't divide by 60..? – BizzyBob May 18 '17 at 16:10
  • Speed (time1 not divide by 60) is 340,464344 – Martin May 18 '17 at 20:43

1 Answers1

0

SOLVED! Many thanks to BizziBob

This is correct working code:

<?php 
$distance="6.03";
$hours="00";
$minutes="34";
$seconds="13";

$time=($hours*3600)+($minutes*60)+$seconds;
$speed=$time/$distance;
$formated=date('i:s', $speed);

echo $formated;
?>
Martin
  • 65
  • 1
  • 8