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

게시판 전체 게시글 원글과 조회수 재설정하기

어떤 특별한 이유에 의해서 게시글의 조회수가 엉키는 경우가 있습니다.
예를 들면 스팸게시글의 침범으로 인한 ...
이렇게 되면 글 번호가 엉키면서 - 번호가 생기기도 하죠.
게시판 관리자 화면에 가면 하나씩 재설정 하는 항목이 있지만, 게시판 수가 많다면 그것도 여간 귀찮은 일이 아닐수 없습니다.
아래 프로그램은 전체 게시판을 모두 재설정하는 방법입니다.

그누보드5 / DB_table_count_reset.php  라는 이름으로 파일을 생성후 브라우저로 실행합니다.


<?php
include_once "_common.php"; 

$dbconn = mysqli_connect(G5_MYSQL_HOST,G5_MYSQL_USER,G5_MYSQL_PASSWORD,G5_MYSQL_DB) ;

if (!$dbconn) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}
//@mysqli_query("set names utf8");   // 한글문제 생기면 주석 해제

$sql = "select * from ".$g5['board_table']." order by bo_table asc "; 
$result = mysqli_query($dbconn,$sql);

while($data = mysqli_fetch_array($result)) { 
    
    $bo_table = $data["bo_table"];
    //echo $data["bo_table"] ."<br>";

    // 게시판의 글 수
    $sql = " select count(*) as cnt from ".$g5['write_prefix'].$bo_table." where wr_is_comment = 0 ";
    $row = sql_fetch($sql);
    $bo_count_write = $row['cnt'];

    // 게시판의 코멘트 수
    $sql = " select count(*) as cnt from ".$g5['write_prefix'].$bo_table." where wr_is_comment = 1 ";
    $row = sql_fetch($sql);
    $bo_count_comment = $row['cnt'];    

    if (isset($_POST['proc_count'])) {
        // 원글을 얻습니다.
        //$sql = " select wr_id from {$g5['write_prefix']}{$bo_table} where wr_is_comment = 0 ";
        $sql = " select a.wr_id, (count(b.wr_parent) - 1) as cnt from ".$g5['write_prefix'].$bo_table." a, ".$g5['write_prefix'].$bo_table." b where a.wr_id=b.wr_parent and a.wr_is_comment=0 group by a.wr_id ";
        $result = mysqli_query($dbconn,$sql);
        for ($i=0; $row=mysqli_fetch_array($result); $i++) {
            /*
            // 코멘트수를 얻습니다.
            $sql2 = " select count(*) as cnt from {$g5['write_prefix']}$bo_table where wr_parent = '{$row['wr_id']}' and wr_is_comment = 1 ";
            $row2 = sql_fetch($sql2);
            */

            mysqli_query($dbconn," update ".$g5['write_prefix'].$bo_table." set wr_comment = '".$row['cnt']."' where wr_id = '".$row['wr_id']."' ");
        }
    }

    // 공지사항에는 등록되어 있지만 실제 존재하지 않는 글 아이디는 삭제합니다.
    $bo_notice = "";
    $lf = "";
    if ($board['bo_notice']) {
        $tmp_array = explode(",", $board['bo_notice']);
        for ($i=0; $i<count($tmp_array); $i++) {
            $tmp_wr_id = trim($tmp_array[$i]);
            $row = sql_fetch(" select count(*) as cnt from ".$g5['write_prefix'].$bo_table." where wr_id = '".$tmp_wr_id."' ");
            if ($row['cnt'])
            {
                $bo_notice .= $lf . $tmp_wr_id;
                $lf = ",";
            }
        }
    }

    $sql = " update ".$g5['board_table']."
                set bo_notice = '".$bo_notice."',
                    bo_count_write = '".$bo_count_write."',
                    bo_count_comment = '".$bo_count_comment."'
              where bo_table = '".$bo_table."' ";
    mysqli_query($dbconn,$sql);
}

echo " 게시판의 원글수와 댓글수 재설정 완료 ";

echo mysqli_error($dbconn);
// close connection
mysqli_close($dbconn);
?>

댓글 작성

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

로그인하기

댓글 4개

좋은정보 감사합니다
굿 정보~ 감사합니다~~
필요했던 것입니다

게시판 목록

그누보드5 팁자료실

글쓰기
🐛 버그신고