테스트 사이트 - 개발 중인 베타 버전입니다

여러 게시판 글 삭제시 total_count 질문입니다~~ 채택완료

lacomparte 7년 전 조회 1,915

일단, 

내글, 내댓글을 보여주는 파일을 만들었습니다 

article_member.php 와 reply_member.php  

이렇게 두개 파일로 만들었는데요, 게시물 가져오는건 아주 잘 됩니다.

 

그런데, 삭제부분을 구현하는데 있어서

조금 문제가 있어서 조언을 구하려고 합니다.

 

article_member.php와 reply_member.php에서

삭제기능을 담당하는 articel_reply_delete.php 라는 파일을 만들었는데요

베이스는 new_delete.php입니다.

 

그런데, A게시판의 게시글과 B게시판의 게시글을 체크 한 뒤

선택 삭제를 하게 되면

bo_count_write 값이 이상하게 들어갑니다;

 

count_write++ 값때문인것 같아서

게시글 마이너스 해주는 쿼리를 for문 밖에 작성하게 되면.. 

A게시판만 카운트가 마이너스 됩니다-_-;

 

저걸 도대체 어디다 넣어줘야 할까요 ㅠ

 

</p>

<p><?php</p>

<p>// articel_reply_delete.php

include_once('./_common.php');</p>

<p>//print_r2($_POST); exit;</p>

<p>if ($mb_id == $member['mb_id'])

    alert("최고관리자만 접근이 가능합니다.");</p>

<p>$board = array();

$save_bo_table = array();</p>

<p>for($i=0;$i<count($_POST['chk_bn_id']);$i++)

{

    // 실제 번호를 넘김

    $k = $_POST['chk_bn_id'][$i];</p>

<p>    $bo_table = $_POST['bo_table'][$k];

    $wr_id    = $_POST['wr_id'][$k];</p>

<p>    $save_bo_table[] = $bo_table;</p>

<p>    $write_table = $g5['write_prefix'].$bo_table;</p>

<p>    if ($board['bo_table'] != $bo_table)

        $board = sql_fetch(" select bo_subject, bo_write_point, bo_comment_point, bo_notice from {$g5['board_table']} where bo_table = '$bo_table' ");</p>

<p>    $sql = " select * from $write_table where wr_id = '$wr_id' ";

    $write = sql_fetch($sql);

    if (!$write) continue;</p>

<p>    // 원글 삭제

    if ($write['wr_is_comment']==0)

    {

        $len = strlen($write['wr_reply']);

        if ($len < 0) $len = 0;

        $reply = substr($write['wr_reply'], 0, $len);</p>

<p>        // 나라오름님 수정 : 원글과 댓글수가 정상적으로 업데이트 되지 않는 오류를 잡아 주셨습니다.

        $sql = " select wr_id, mb_id, wr_is_comment from $write_table where wr_parent = '{$write['wr_id']}' order by wr_id ";

        $result = sql_query($sql);</p>

<p>        while ($row = sql_fetch_array($result))

        {

            // 원글이라면

            if (!$row['wr_is_comment'])

            {

                // 원글 포인트 삭제

                if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '쓰기'))

                    insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글삭제");</p>

<p>                // 업로드된 파일이 있다면 파일삭제

                /*

                $sql2 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ";

                $result2 = sql_query($sql2);

                while ($row2 = sql_fetch_array($result2)) {

                    @unlink(G5_DATA_PATH.'/file/'.$bo_table.'/'.$row2['bf_file']);

                }

                */</p>

<p>                // 업로드된 파일이 있다면 파일삭제

                $sql2 = " select * from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ";

                $result2 = sql_query($sql2);

                while ($row2 = sql_fetch_array($result2)) {

                    @unlink(G5_DATA_PATH.'/file/'.$bo_table.'/'.$row2['bf_file']);

                    // 썸네일삭제

                    if(preg_match("/\.({$config['cf_image_extension']})$/i", $row2['bf_file'])) {

                        delete_board_thumbnail($bo_table, $row2['bf_file']);

                    }

                }</p>

<p>                // 게시글 삭제

                $sql_delete = " delete from $write_table where wr_parent = '{$write['wr_id']}' ";

                sql_query($sql_delete);</p>

<p>                // 에디터 썸네일 삭제

                delete_editor_thumbnail($row['wr_content']);</p>

<p>                // 파일테이블 행 삭제

                sql_query(" delete from {$g5['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' ");</p>

<p>                // 2018-02-06 게시물 삭제시 member table에 mb_article 디스카운트

                if(!$gr_id = 'shop') {

                    sql_query("UPDATE $g5[member_table] SET mb_article=mb_article-1 WHERE mb_id='$member[mb_id]'");

                }</p>

<p>                $count_write++;

            }

            else

            {

                // 2018-02-27 원글 id 구하기

                $sql_d = "SELECT mb_id FROM {$write_table} WHERE wr_is_comment = 0 AND wr_id = $write[wr_parent]";

                $row_d = sql_fetch($sql_d);</p>

<p>                // 댓글 포인트 삭제

                if ($row_d['mb_id'] != $write['mb_id']) {

                    if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '댓글'))

                        insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 댓글삭제");

                }

                $count_comment++;

            }

        }</p>

<p>        if ($pressed == '선택내용삭제') {

            // 게시글 내용만 삭제

            sql_query(" update $write_table set wr_subject =  '".G5_TIME_YMDHIS." - 본인 요청으로 인한 삭제 (냉무) ☆', wr_content = '', wr_name='본인요청삭제☆' where wr_id = '{$write['wr_id']}' ");

        } else {

            // 게시글 삭제

            sql_query(" delete from $write_table where wr_parent = '{$write['wr_id']}' ");

        }</p>

<p>        // 최근게시물 삭제

        sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_parent = '{$write['wr_id']}' ");</p>

<p>        // 스크랩 삭제

        sql_query(" delete from {$g5['scrap_table']} where bo_table = '$bo_table' and wr_id = '{$write['wr_id']}' ");</p>

<p>        // 공지사항 삭제

        $notice_array = explode(",", trim($board['bo_notice']));

        $bo_notice = "";

        $lf = '';

        for ($k=0; $k<count($notice_array); $k++) {

            if ((int)$write['wr_id'] != (int)$notice_array[$k])

                $bo_notice .= $nl.$notice_array[$k];</p>

<p>            if($bo_notice)

                $lf = ',';

        }

        $bo_notice = trim($bo_notice);

        sql_query(" update {$g5['board_table']} set bo_notice = '$bo_notice' where bo_table = '$bo_table' ");

        

        // 서로 다른 게시판을 삭제할때 게시판 한군대만 카운트 되는 문제.

        if ($count_write > 0 || $count_comment > 0) {

            sql_query(" update {$g5['board_table']} set bo_count_write = bo_count_write - '$count_write', bo_count_comment = bo_count_comment - '$count_comment' where bo_table = '$bo_table' ");

        }

    }

    else // 댓글 삭제

    {

        //--------------------------------------------------------------------

        // 댓글 삭제시 답변 댓글 까지 삭제되지는 않음

        //--------------------------------------------------------------------

        //print_r2($write);</p>

<p>        // 2018-02-27 원글 id 구하기

        $sql_d = "SELECT mb_id FROM {$write_table} WHERE wr_is_comment = 0 AND wr_id = $write[wr_parent]";

        $row_d = sql_fetch($sql_d);</p>

<p>        $comment_id = $wr_id;</p>

<p>        $len = strlen($write['wr_comment_reply']);

        if ($len < 0) $len = 0;

        $comment_reply = substr($write['wr_comment_reply'], 0, $len);</p>

<p>        // 2018-02-27 만약 원글과 댓글 아이디가 다르다면 댓글 포인트 차감

        if ($row_d['mb_id'] != $write['mb_id']) {

            if (!delete_point($write['mb_id'], $bo_table, $comment_id, '댓글')) {

                insert_point($write['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write[wr_parent]}-{$comment_id} 댓글삭제");

            }

        }</p>

<p>        // 댓글 삭제

        sql_query(" delete from $write_table where wr_id = '$comment_id' ");</p>

<p>        // 댓글가 삭제되므로 해당 게시물에 대한 최근 시간을 다시 얻는다.

        $sql = " select max(wr_datetime) as wr_last from $write_table where wr_parent = '{$write['wr_parent']}' ";

        $row = sql_fetch($sql);</p>

<p>        // 원글의 댓글 숫자를 감소

        sql_query(" update $write_table set wr_comment = wr_comment - 1, wr_last = '$row[wr_last]' where wr_id = '{$write['wr_parent']}' ");</p>

<p>        // 댓글 숫자 감소

        sql_query(" update {$g5['board_table']} set bo_count_comment = bo_count_comment - 1 where bo_table = '$bo_table' ");</p>

<p>        // 새글 삭제

        sql_query(" delete from {$g5['board_new_table']} where bo_table = '$bo_table' and wr_id = '$comment_id' ");

    }

}</p>

<p>

$save_bo_table = array_unique($save_bo_table);

foreach ($save_bo_table as $key=>$value) {

    delete_cache_latest($value);

}

//goto_url($_SERVER['HTTP_REFERER']);

?></p>

<p>

댓글을 작성하려면 로그인이 필요합니다.

답변 1개

채택된 답변
+20 포인트
o
7년 전

12라인 위에 아래를 추가해 보세요
//추가 ------------------- 
$count_comment=$count_write=0;
//------------------------

012
    $k = $_POST['chk_bn_id'][$i];
013
    $bo_table = $_POST['bo_table'][$k];
014
    $wr_id    = $_POST['wr_id'][$k];
015
    $save_bo_table[] = $bo_table;
016
    $write_table = $g5['write_prefix'].$bo_table;
 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

l
lacomparte
7년 전
감사합니다.ㅠ

왜 저걸 써줘야 원하는 기능이 되는지는 소스분석좀 해봐야겠네요 ㅠ

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인