게시물에 상세화면 들어갈때 처음 한번만 자동댓글이 등록되도록 하려면?

게시물에 상세화면 들어갈때 처음 한번만 자동댓글이 등록되도록 하려면?

QA

게시물에 상세화면 들어갈때 처음 한번만 자동댓글이 등록되도록 하려면?

본문

특정 게시판의 게시물목록에서 게시물을 선택하여 상세화면으로 들어가면

그 사람의 이름으로 댓글이 자동으로 등록되도록 구현하려고

bbs/view.php 상단에 아래의 코드를 넣고 테스트 해보니 동작하는것 같습니다.

 

그런데, 자동으로 등록되는 댓글은 중복등록되지 않고 한번만 등록되도록 하고싶습니다.

제가 실력이 부족한데,

사용자별로 자동 댓글이 처음에 한번만 등록되고 이후부터는 자동댓글은 등록되지 않도록 구현하려면

어떤 코드를 어디에 추가해야 할까요? 고수님들의 많은 도움을 부탁드립니다.

 

 if($bo_table == "free") {
        if($w == ''){
                $wr_write = get_write($write_table, $wr_id);//원글정보
                $wr_write_content = "여기에 댓글 내용 지정하시면 됩니다."; //댓글내용
                $wr_write_cname = $member['mb_name'];//등록자명
                $wr_write_mb_id = $config['cf_admin'];//등록아이디
                $wr_write_password = sql_password(G5_SERVER_TIME);//패스워드
                $sql = " insert into $write_table
                            set ca_name = '$wr_write[ca_name]',
                                wr_num = '$wr_write[wr_num]',
                                wr_parent = '$wr_id',
                                wr_is_comment = '1',
                                wr_comment = '1',
                                wr_content = '$wr_write_content',
                                mb_id = '$wr_write_mb_id',
                                wr_password = '$wr_write_password',
                                wr_name = '$wr_write_cname',
                                wr_datetime = '".G5_TIME_YMDHIS."',
                                wr_ip = '" . $_SERVER['REMOTE_ADDR'] . " ' ";
                sql_query($sql);
                
                // 원글에 코멘트수 증가
                sql_query(" update $write_table set wr_comment = wr_comment + 1, wr_last = '".G5_TIME_YMDHIS."' where wr_id = '$wr_id' ");
                sql_query(" update {$g5['board_new_table']} set as_comment = as_comment + 1 where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ", false);
                // 코멘트 1 증가
                sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
        }
}

이 질문에 댓글 쓰기 :

답변 3


 if($bo_table == "free") {
        if($w == ''){
                $wr_write = get_write($write_table, $wr_id);//원글정보
                $wr_write_content = "여기에 댓글 내용 지정하시면 됩니다."; //댓글내용
                $wr_write_cname = $member['mb_name'];//등록자명
                $wr_write_mb_id = $config['cf_admin'];//등록아이디
                $wr_write_password = sql_password(G5_SERVER_TIME);//패스워드
                
                $sql = " select wr_id from $write_table 
                            where wr_parent = '$wr_id' 
                                and wr_is_comment = '1',
                                and wr_comment = '1',
                                and mb_id = '$wr_write_mb_id',
                                and wr_name = '$wr_write_cname' ";
                $row = sql_fetch($sql);
                if(!$row['wr_id']) {
                    $sql = " insert into $write_table
                                set ca_name = '$wr_write[ca_name]',
                                    wr_num = '$wr_write[wr_num]',
                                    wr_parent = '$wr_id',
                                    wr_is_comment = '1',
                                    wr_comment = '1',
                                    wr_content = '$wr_write_content',
                                    mb_id = '$wr_write_mb_id',
                                    wr_password = '$wr_write_password',
                                    wr_name = '$wr_write_cname',
                                    wr_datetime = '".G5_TIME_YMDHIS."',
                                    wr_ip = '" . $_SERVER['REMOTE_ADDR'] . " ' ";
                    sql_query($sql);
                    
                    // 원글에 코멘트수 증가
                    sql_query(" update $write_table set wr_comment = wr_comment + 1, wr_last = '".G5_TIME_YMDHIS."' where wr_id = '$wr_id' ");
                    sql_query(" update {$g5['board_new_table']} set as_comment = as_comment + 1 where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ", false);
                    // 코멘트 1 증가
                    sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
                }
        }
}

너무 감사드립니다. 덕분에 조금씩 되어가고 있습니다.
알려주신 코드에서 select 문의 and 절에 있는 콤마는 지워니 잘 됩니다.

다만, 코멘트를 insert할때 wr_comment = 1 로 하다보니까 댓글 목록이 많을 경우 자동댓글이 마지막에 나오는 것이 아니라 앞쪽 중간에 나오게 되는군요.

wr_comment는 댓글 작성순서대로 증가시키고, 자동댓글여부를 다른 필드로 인식하는 방법이 없을까요?(확장필드를 사용한다든지....)

select 에서 and wr_comment = '1' 삭제하시구요..
insert 에서 wr_comment = '$tmp_comment', 로 수정해주세요.
아래 구문의 그 위쪽에 추가해야 합니다.


        $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'];

최종소스

$cmtArr[0] = "멋진 작품 입니다. 감사한 마음으로 감상하고 갑니다.";
$cmtArr[1] = "멋진 시선의 작품에 감사드립니다.";
$cmtArr[2] = "멋진 시선의 작품에 감사드립니다.";
$pjj = rand(0,2);

 

 if($bo_table == "free") {

        if($w == ''){
                $wr_write = get_write($write_table, $wr_id);//원글정보
                $wr_write_content = $cmtArr[$pjj]; //댓글내용
                $wr_write_cname = $member['mb_name'];//등록자명
                $wr_write_mb_id = $config['cf_admin'];//등록아이디
                $wr_write_password = sql_password(G5_SERVER_TIME);//패스워드
                $sql = " select wr_id, max(wr_comment) from $write_table 
                            where wr_parent = '$wr_id' 
                                and wr_is_comment = '1'
                            /*    and wr_comment = '1'  */
                                and mb_id = '$wr_write_mb_id'
                                and wr_name = '$wr_write_cname' 
                                and wr_10 = 'auto' ";
                $row = sql_fetch($sql);
                //echo $sql . "<br>";
                if(!$row['wr_id']) {
                        $sql = " select max(wr_comment) maxnum from $write_table  where wr_parent = '$wr_id'  ";
                        $row = sql_fetch($sql);
                        $maxnum = $row['maxnum'];

                        $sql = " insert into $write_table
                                        set ca_name = '$wr_write[ca_name]',
                                        wr_num = '$wr_write[wr_num]',
                                        wr_parent = '$wr_id',
                                        wr_is_comment = '1',
                                        wr_10 = 'auto',
                                        wr_comment = '$maxnum',
                                        wr_content = '$wr_write_content',
                                        mb_id = '$wr_write_mb_id',
                                        wr_password = '$wr_write_password',
                                        wr_name = '$wr_write_cname',
                                        wr_datetime = '".G5_TIME_YMDHIS."',
                                        wr_ip = '" . $_SERVER['REMOTE_ADDR'] . " ' ";
                        sql_query($sql);

                        // 원글에 코멘트수 증가
                        sql_query(" update $write_table set wr_comment = wr_comment + 1, wr_last = '".G5_TIME_YMDHIS."' where wr_id = '$wr_id' ");
                        sql_query(" update {$g5['board_new_table']} set as_comment = as_comment + 1 where bo_table = '{$bo_table}' and wr_id = '{$wr_id}' ", false);

                        // 코멘트 1 증가
                        sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment + 1 where bo_table = '$bo_table' ");
                }
        }
}

답변을 작성하시기 전에 로그인 해주세요.
전체 123,592 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT