자동으로 댓글에 댓글을 달려면 어떻게 해야될까요?
본문
안녕하세요.
자동으로 댓글에 댓글을 달려고 하는데요.
A라는 사람이 댓글을 달았으면 그 댓글에 "포인트 당첨" 뭐 이런 멘트댓글을 자동으로 달게 하는거요.
아래 소스로 해보니까 달리기는 하는데, 문제가 자동으로 달린 댓글에는 추가답변댓글이 안달려요.
그리고 이미 대댓글이 있는 첫번째 댓글을 선택해도 안되고요.
"더 이상 답변하실 수 없습니다. 답변은 26개 까지만 가능합니다." 이런 에러가 나와요.
왜 그런지 알 수가 없어요..ㅜ.ㅜ
댓글을 등록하는 함수는 따로 없나봐요..
이런 형태로요.. reply_insert(b_table,wr_id,cmt_id, mb_id, wr_content);
그럼 굉장히 편할텐데..
이소스 긁어와서 했었거든요..
// 댓글 답변
if ($comment_id)
{
$sql = " select wr_id, wr_comment, wr_comment_reply from $write_table
where wr_id = '$comment_id' ";
$reply_array = sql_fetch($sql);
if (!$reply_array['wr_id'])
json_err('추첨할 댓글이 없습니다.\\n\\n추첨하는 동안 댓글이 삭제되었을 수 있습니다.');
$tmp_comment = $reply_array['wr_comment'];
if (strlen($reply_array['wr_comment_reply']) == 5)
json_err('더 이상 답변하실 수 없습니다.\\n\\n답변은 5단계 까지만 가능합니다.');
$reply_len = strlen($reply_array['wr_comment_reply']) + 1;
if ($board['bo_reply_order']) {
$begin_reply_char = 'A';
$end_reply_char = 'Z';
$reply_number = +1;
$sql = " select MAX(SUBSTRING(wr_comment_reply, $reply_len, 1)) as reply
from $write_table
where wr_parent = '$wr_id'
and wr_comment = '$tmp_comment'
and SUBSTRING(wr_comment_reply, $reply_len, 1) <> '' ";
}
else
{
$begin_reply_char = 'Z';
$end_reply_char = 'A';
$reply_number = -1;
$sql = " select MIN(SUBSTRING(wr_comment_reply, $reply_len, 1)) as reply
from $write_table
where wr_parent = '$wr_id'
and wr_comment = '$tmp_comment'
and SUBSTRING(wr_comment_reply, $reply_len, 1) <> '' ";
}
if ($reply_array['wr_comment_reply'])
$sql .= " and wr_comment_reply like '{$reply_array['wr_comment_reply']}%' ";
$row = sql_fetch($sql);
if (!$row['reply'])
$reply_char = $begin_reply_char;
else if ($row['reply'] == $end_reply_char) // A~Z은 26 입니다.
json_err('더 이상 답변하실 수 없습니다.\\n\\n답변은 26개 까지만 가능합니다.');
else
$reply_char = chr(ord($row['reply']) + $reply_number);
$tmp_comment_reply = $reply_array['wr_comment_reply'] . $reply_char;
}
else
{
$sql = " select max(wr_comment) as max_comment from $write_table
where wr_parent = '$wr_id' and wr_is_comment = 1 ";
$row = sql_fetch($sql);
//$row[max_comment] -= 1;
$row['max_comment'] += 1;
$tmp_comment = $row['max_comment'];
$tmp_comment_reply = '';
}
$wr_subject = get_text(stripslashes($wr['wr_subject']));
$sql = " insert into $write_table
set ca_name = '{$wr['ca_name']}',
wr_option = '$wr_secret',
wr_num = '{$wr['wr_num']}',
wr_reply = '',
wr_parent = '$wr_id',
wr_is_comment = 1,
wr_comment = '$tmp_comment',
wr_comment_reply = '$tmp_comment_reply',
wr_subject = '',
wr_content = '$wr_content',
mb_id = '$mb_id',
wr_password = '$wr_password',
wr_name = '$wr_name',
wr_email = '$wr_email',
wr_homepage = '$wr_homepage',
wr_datetime = '".G5_TIME_YMDHIS."',
wr_last = '',
wr_ip = '{$_SERVER['REMOTE_ADDR']}',
wr_1 = '$wr_1',
wr_2 = '$wr_2',
wr_3 = '$wr_3',
wr_4 = '$wr_4',
wr_5 = '$wr_5',
wr_6 = '$wr_6',
wr_7 = '$wr_7',
wr_8 = '$wr_8',
wr_9 = '$wr_9',
wr_10 = '$wr_10' ";
sql_query($sql, true);
$comment_id = mysql_insert_id();
// 원글에 댓글수 증가 & 마지막 시간 반영
sql_query(" update $write_table set wr_comment = wr_comment + 1, wr_last = '".G5_TIME_YMDHIS."' where wr_id = '$wr_id' ");
// 새글 INSERT
sql_query(" insert into {$g5['board_new_table']} ( bo_table, wr_id, wr_parent, bn_datetime, mb_id ) values ( '$bo_table', '$comment_id', '$wr_id', '".G5_TIME_YMDHIS."', '{$member['mb_id']}' ) ");
// 댓글 1 증가
sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
어디를 고쳐야 할까요?