Bir php kodlaması hakkında yardım eder misiniz?
2
●114
- 17-11-2025, 17:10:17my_comments.php linkini değiştir
<a href="content.php?id=<?= $cm['content_id'] ?>&comment_id=<?= $cm['id'] ?>#comment-<?= $cm['id'] ?>"> <i class="fa fa-arrow-right"></i> </a>content.php içinde, yorumun hangi sayfada olduğunu hesapla comment_list.php içinde kaç yorum gösteriyorsan (ör: 10), burada da aynı değeri kullanacağız.
// content.php içinde, $content_id belirlendikten sonra bir yere ekle $commentsPerPage = 10; // comment_list.php'de kaç yorum gösteriyorsan OLSUN if (isset($_GET['comment_id']) && is_numeric($_GET['comment_id'])) { $targetCommentId = (int)$_GET['comment_id']; // Bu yorumdan önceki (ve kendisi dahil) yorum sayısını bul $stmt = $pdo->prepare(" SELECT COUNT(*) FROM comments WHERE content_id = ? AND id <= ? "); $stmt->execute([$content_id, $targetCommentId]); $position = (int)$stmt->fetchColumn(); if ($position > 0) { $page = (int)ceil($position / $commentsPerPage); // URL'de page yoksa veya yanlışsa düzelterek redirect et if (!isset($_GET['page']) || (int)$_GET['page'] !== $page) { // sonsuz redirect olmasın diye comment_id parametresini kaldırıyoruz $baseUrl = "content.php?id={$content_id}&page={$page}#comment-{$targetCommentId}"; header("Location: {$baseUrl}"); exit; } } }