diff --git a/app.php b/app.php index 5438b01..6afcc90 100644 --- a/app.php +++ b/app.php @@ -35,16 +35,20 @@ $resultImages = $conn->query($sqlImages); $sqlReviews = "SELECT * FROM reviews WHERE app_id = $appId ORDER BY created_at DESC"; $resultReviews = $conn->query($sqlReviews); +// 获取评分分布 +$sqlRatingDistribution = "SELECT rating, COUNT(*) as count FROM reviews WHERE app_id = $appId GROUP BY rating ORDER BY rating DESC"; +$resultRatingDistribution = $conn->query($sqlRatingDistribution); +$ratingDistribution = []; +while ($row = $resultRatingDistribution->fetch_assoc()) { + $ratingDistribution[$row['rating']] = $row['count']; +} + // 处理评价提交 if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating'])) { $rating = $_POST['rating']; $ipAddress = $_SERVER['REMOTE_ADDR']; - $insertSql = "INSERT INTO reviews (app_id, ip_address, rating) VALUES ($appId, '$ipAddress', $rating)"; - if ($conn->query($insertSql) === TRUE) { - header('Location: app.php?id=$appId'); - exit; - } + $insertSql = "INSERT INTO reviews (app_id, rating) VALUES ($appId, $rating)"; if ($conn->query($insertSql) === TRUE) { header("Location: app.php?id=$appId"); exit; } } ?> @@ -55,6 +59,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rating'])) {
评分: /5
-评价时间:
+评价时间:
+