I don't know any PHP, but I needed an API. My friend made one, but I need the average time stamps (of course, just if query found more than one row). From my mysql database I get time stamps (00:34:51) as a string.
I think I know what to do, but I am so incapable in PHP that I just can't fix it myself.
This is the web API
<?php
// import connect
require_once '../db_connect.php';
// api input
$name = $_POST['name'];
$country = $_POST['country'];
$race = $_POST['race_type'];
$return = [];
// execute query
$stmt = $conn->prepare("SELECT Swim,Bike,Run,Overall FROM test WHERE Name = ? AND Country = ? AND Race = ?");
$stmt->bind_param("sss", $name, $country, $race);
$stmt->execute();
$result = $stmt->get_result();
// search in data
while ($row = $result->fetch_assoc()) {
if ($row['Swim'] < $row['Bike'] && $row['Swim'] < $row['Run']) {
$best = $row['Swim'];
} else if ($row['Bike'] < $row['Swim'] && $row['Bike'] < $row['Run']) {
$best = $row['Bike'];
} else {
$best = $row['Run'];
}
array_push($return, [
'swim' => $row['Swim'],
'bike' => $row['Bike'],
'run' => $row['Run'],
'overall' => $row['Overall'],
'best' => $best
]);
}
// return data
echo json_encode($return);
$stmt->close();
$conn->close();
die();
And this is how one line of my mySQL database looks like
ID Race RaceDate Name Country Div Rank Gender Rank Overall Rank Swim Bike Run Finish
1 70.3 Pula 20170917 Stefan Haubner DEU 1 1 1 0:00:34 2:23:03 1:20:33 3:46:33