리스트에서 댓글의 답글이 출력이 안됨~
본문
리스트에서 댓글을 출력하기 위해 아래와 같이 했는데 댓글은 출력이 되는데 대글에 대한 답글이 출력이 안됨~~디비에는 wr_comment_reply 에 A 로 입력되어 있음~~
<?php
// 댓글 조회
$sql = "SELECT * FROM {$g5['write_prefix']}{$bo_table}
WHERE wr_parent = '{$list[$i]['wr_id']}' AND wr_is_comment = 1
ORDER BY wr_comment_reply ASC, wr_datetime ASC"; // wr_comment_reply로 정렬
$comments = sql_query($sql);
while ($comment = sql_fetch_array($comments)) {
$comment_content = $comment['wr_content'];
$comment_content = applyEmoticons($comment_content, $emoticons); // 이모티콘 적용
if ($comment['wr_option'] == 'secret' && !$is_member) {
$comment_content = '<i class="fa fa-lock" aria-hidden="true"></i> 비밀글입니다.';
}
// wr_comment_reply 값이 있으면 답글로 간주
$is_reply = !empty($comment['wr_comment_reply']); // wr_comment_reply 값이 있으면 true
$cmt_depth = $is_reply ? strlen($comment['wr_comment_reply']) * 20 : 0; // 들여쓰기 깊이 계산
// 답글의 깊이에 따라 들여쓰기 적용
$cmt_depth = $is_reply ? (strlen($comment['wr_comment_reply']) * 20) : 0;
?>
<div class="comment" style="margin-left: <?php echo $cmt_depth; ?>px;">
<div class="comment-header">
<span class="comment-author"><?php echo get_text($comment['wr_name']); ?></span>
<span class="comment-date"><?php echo $comment['wr_datetime']; ?></span>
</div>
<div class="comment-content">
<?php echo $comment_content; ?>
</div>
</div>
답변 3
wr_parent 값은 동일하게 존재하나요?
해당 데이터값이 어떻게 보이는지 정확히 알수 없기에 쿼리 구조상은 나와야 하는게 맞는걸로 보입니다.
일단 쿼리 자체로는 나와야하는게 맞을거 같은데 쿼리를 phpmyadmin이나 외부프로그램으로 해봐도 동일하게 안나오시나요?
혹시나 해서 해당쿼리 제가 따로 해봐도 나오는게 정상이네요. 말씀하신데로 둘 다 wr_is_comment 1이라서 나와야 하는데 정렬순서는 생각하신데로가 아닐수 있습니다. 다 나오는데 정렬이 제대로 안된건지 확인을 한번 해보셔야 할 거 같습니다.
답변을 작성하시기 전에 로그인 해주세요.