diff --git a/api.php b/api.php index 1882fe1..3d8cca3 100644 --- a/api.php +++ b/api.php @@ -28,7 +28,7 @@ if (isset($_GET['action'])) { // 处理应用列表请求 if ($action === 'list' && $requestMethod === 'GET') { - $sql = "SELECT apps.id, apps.name, apps.description, apps.age_rating, apps.platform, AVG(reviews.rating) as avg_rating + $sql = "SELECT apps.id, apps.name, apps.description, apps.age_rating, AVG(reviews.rating) as avg_rating FROM apps LEFT JOIN reviews ON apps.id = reviews.app_id"; @@ -48,7 +48,7 @@ if (isset($_GET['action'])) { // 平台过滤 if (isset($_GET['platform'])) { $platform = $_GET['platform']; - $conditions[] = "apps.platform = ?"; + // Removed platform condition - column does not exist $stmtParams[] = &$platform; $paramTypes .= 's'; } @@ -79,7 +79,7 @@ if (isset($_GET['action'])) { } // 添加分页 - $sql .= " GROUP BY apps.id, apps.name, apps.description, apps.age_rating, apps.platform ORDER BY apps.created_at DESC LIMIT ? OFFSET ?"; + $sql .= " GROUP BY apps.id, apps.name, apps.description, apps.age_rating ORDER BY apps.created_at DESC LIMIT ? OFFSET ?"; $stmtParams[] = &$limit; $stmtParams[] = &$offset; $paramTypes .= 'ii'; @@ -137,11 +137,11 @@ if (isset($_GET['action'])) { $appId = $_GET['id']; error_log("Requesting app details for ID: $appId"); - $sqlApp = "SELECT apps.id, apps.name, apps.description, apps.age_rating, apps.platform, apps.created_at, AVG(reviews.rating) as avg_rating + $sqlApp = "SELECT apps.id, apps.name, apps.description, apps.age_rating, apps.created_at, AVG(reviews.rating) as avg_rating FROM apps LEFT JOIN reviews ON apps.id = reviews.app_id WHERE apps.id = ? - GROUP BY apps.id, apps.name, apps.description, apps.age_rating, apps.platform, apps.created_at"; + GROUP BY apps.id, apps.name, apps.description, apps.age_rating, apps.created_at"; $stmt = $conn->prepare($sqlApp); $stmt->bind_param("i", $appId); $stmt->execute(); diff --git a/app.php b/app.php index aa9931c..9e3d465 100644 --- a/app.php +++ b/app.php @@ -31,6 +31,18 @@ if (!$app) { // 处理评价加载请求 if (isset($_GET['action']) && $_GET['action'] === 'load_reviews') { header('Content-Type: text/html; charset=UTF-8'); + // 获取评论数据 + $sqlReviews = "SELECT * FROM reviews WHERE app_id = ? ORDER BY created_at DESC, id DESC LIMIT 10 OFFSET ?"; + $stmt = $conn->prepare($sqlReviews); + $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; + $stmt->bind_param("ii", $appId, $offset); + $stmt->execute(); + $resultReviews = $stmt->get_result(); + + if (!$resultReviews) { + die("Error fetching reviews: " . htmlspecialchars($conn->error)); + } + while ($review = $resultReviews->fetch_assoc()) { ?>