diff --git a/api.php b/api.php index 0f63ab5..985b02b 100644 --- a/api.php +++ b/api.php @@ -787,27 +787,29 @@ case 'save_config': break; case 'get_films': - // 1. Récupération des critiques - $critiques = $pdo->query("SELECT id, title, year, director, poster, rating, review, NULL AS description, streaming, 'critique' AS type, NULL AS format FROM critiques ORDER BY id DESC")->fetchAll(); - - // Correction des notes (format entier si rond) - foreach ($critiques as $row) { - if ($row['rating'] !== null) { - $ratingVal = (float)$row['rating']; - $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal; + // 1. Récupération des critiques + $critiques = $pdo->query("SELECT id, title, year, director, poster, rating, review, NULL AS description, streaming, 'critique' AS type, NULL AS format FROM critiques ORDER BY id DESC")->fetchAll(); + + // CORRECTION : Utilisation du & pour modifier le tableau original + foreach ($critiques as $row) { + if ($row['rating'] !== null) { + $ratingVal = (float)$row['rating']; + $row['rating'] = ($ratingVal == floor($ratingVal)) ? (int)$ratingVal : $ratingVal; + } } - } - unset($row); + unset($row); // Sécurité pour libérer la référence - // 2. Récupération de la vidéothèque - $videotheque = $pdo->query("SELECT id, title, year, director, poster, NULL AS rating, NULL AS review, description, NULL AS streaming, 'videotheque' AS type, format FROM videotheque ORDER BY id DESC")->fetchAll(); + // 2. Récupération de la vidéothèque + $videotheque = $pdo->query("SELECT id, title, year, director, poster, NULL AS rating, NULL AS review, description, NULL AS streaming, 'videotheque' AS type, format FROM videotheque ORDER BY id DESC")->fetchAll(); - // 3. Retourne les deux listes séparées - echo json_encode([ - 'critiques' => $critiques, - 'videotheque' => $videotheque - ]); - break; + // LOGGING : Utile pour voir dans php_errors.log si les tables sont vides + error_log("API get_films - Critiques trouvées: " . count($critiques) . " | Vidéothèque: " . count($videotheque)); + + echo json_encode([ + 'critiques' => $critiques, + 'videotheque' => $videotheque + ]); + break; case 'save_film': checkAuth($pdo);