<?php

    $json = file_get_contents('php://input');   
    $obj = json_decode($json);
    $id = $obj->flag;
    // Returns a Json
    header('Content-Type: application/json');
    
    $conn = new mysqli("directoriofitness.com.mx", "direct18", "L4LL4v3M@3str@","direct18_ProGymWorkout");
    $conn -> set_charset("utf8");
    $query = "SELECT id_registroentrenamiento, TIMESTAMPDIFF(HOUR,fecha_entrenamiento,NOW()) AS 'dif' 
        FROM registro_entrenamientos 
        WHERE idprograma = '$obj->id_p'
        ORDER BY id_registroentrenamiento DESC
        limit 1";
    
    $res = $conn->query($query);
    
    $row = $res->fetch_assoc();
    
    $diferencia = $row["dif"];
    echo $diferencia = !empty($diferencia) ? $diferencia : 'nada';
    
    $conn->close();
?>