list.php 리프레시 마다 카운트 수 조정되게 하기 채택완료

adm 페이지에 있는 그 부분만 떼다 리스트에 붙이면 될 줄 알고 해봤는데 안되네요?

 

이것말고 더 넣어야할 코드가 있나요? 


Copy
// 원글을 얻습니다.
$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 = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++) {
    sql_query(" update {$g5['write_prefix']}{$bo_table} set wr_comment = '{$row['cnt']}' where wr_id = '{$row['wr_id']}' ");
}

답변 1개

채택된 답변
+20 포인트

게시판의 글수, 코맨트 수를 업데이트 하고 싶으신 거라면

Copy
// 게시판의 글 수
    $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'];

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

 

리스트 접속 시 마다 이 query 를 실행 하는 것이라면 디비 부하가 생길 수 있습니다.

crontab 으로 해당 기능을 따로 시키거나, 하루 한두번 실행 하도록 하는 것이 좋습니다

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

답변에 대한 댓글 1개

innoDB특성상, 페이징 때문에
bo_count_write가 필요하지만
bo_count_comment는 어디에 쓰이나요?

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

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

로그인
🐛 버그신고