I fetch various rows from the database (the column is formatted as datetime) and formatted it to time only. Now I want to add all the row into one PHP variable, how can I achieve this?
$total_time = $this->fetchTime();
public function fetchTime(){
$catch = 0;
$db = $this->getConn();
$statement = $db->prepare("SELECT log_in FROM attendance");
$statement->execute();
while ($result = $statement->fetch()){
$catch += $result[0]; //This is the part where I do not know how to add time
}
return $catch;
}
this might help you
public function fetchTime(){
$catch = "";
$db = $this->getConn();
$statement = $db->prepare("SELECT log_in FROM attendance");
$statement->execute();
while ($result = $statement->fetch()){
$catch.= $result[0]; //This is the part where I do not know how to add time
}
return $catch;
}