'Connessione al database fallita']); exit; } // Check if id_utente is provided if (isset($_POST['id_utente'])) { $id_utente = intval($_POST['id_utente']); // Query to fetch class details with necessary fields $sql = " SELECT bc.idbookingclass, bc.bookingstart, bc.status, bc.lostlesson, bc.prevbookingstart, bc.idorder, ob.order_date_created, s.servicename, s.day, s.time FROM bookingclass bc LEFT JOIN orderbook ob ON bc.idorder = ob.idorderbook LEFT JOIN service s ON bc.idservice = s.idservice WHERE bc.iduser = $id_utente ORDER BY bc.bookingstart DESC "; $result = mysqli_query($conn, $sql); if (!$result) { ob_end_clean(); header('Content-Type: application/json'); echo json_encode(['error' => 'Errore nella query: ' . mysqli_error($conn)]); exit; } $classes = []; // Fetch all rows and store in an array while ($row = mysqli_fetch_assoc($result)) { $classes[] = $row; } // Clear the output buffer, set the header, and output JSON ob_end_clean(); header('Content-Type: application/json'); echo json_encode($classes); mysqli_close($conn); exit; } // If id_utente is not provided, return an error ob_end_clean(); header('Content-Type: application/json'); echo json_encode(['error' => 'ID utente non fornito']); mysqli_close($conn); exit; ?>