여러게시판의 게시물 숫자 합계 자동출력

여러게시판의 게시물 숫자 합계 자동출력

QA

여러게시판의 게시물 숫자 합계 자동출력

답변 7

본문

예를들어서 

bbs01 , bbs02, bbs03, bbs04, bbs05 까지의 게시판이 있고,

이 외에도 notice, free, gallery 등의 여러 게시판이 있다고 할때요.

 

지정한 게시판들에 대해서 게시물 수를 한번에 카운트할 수 있는 방법이 있을까요?

예를들어 bbs로 시작하는 게시판이 모두 후기 게시판이라고 하면 

 

총 Review 수 :  [bbs01 + bbs02 + bbs03 + bbs04 + bbs05]

 

이렇게 보여줄 수 있는지요?

코드를 어떻게 작성해야 할까요?

이 질문에 댓글 쓰기 :

답변 7

$row=sql_fetch("select sum(bo_count_write) as cnt from {$g5['board_table']} where bo_table like 'bbs%' ");
echo $row['cnt'];

모든 게시물 수를 구한다면,

$row = sql_fetch(" select sum(bo_count_write) as cnt from {$g5['board_table']} ");
echo $row['cnt'];

 

특정게시판은 

$row = sql_fetch(" select sum(bo_count_write) as cnt from {$g5['board_table']} where bo_table in ('notice', 'free', 'gallery') ");
echo $row['cnt'];

총 Review 수 : 

<?php
$row = sql_fetch("select sum(bo_count_write) as cnt from g5_board where bo_table IN('bbs01','bbs02','bbs03','bbs04','bbs05')"); 
echo "".number_format($row[cnt])."";
?>

 

<?php
$row = sql_fetch("select sum(bo_count_write) as cnt from g5_board where bo_table IN('notice','free','gallery')"); 
echo "".number_format($row[cnt])."";
?>


// 'bbs'로 시작하는 게시판 목록 가져오기
$sql = "SELECT bo_table FROM g5_board WHERE bo_table LIKE 'bbs%'";
$result = sql_query($sql);
$total_count = 0;
while ($row = sql_fetch_array($result)) {
    $table_name = 'g5_write_' . $row['bo_table'];
    // 해당 게시판의 게시글 수 가져오기
    $count_sql = "SELECT COUNT(*) AS cnt FROM {$table_name}";
    $count_result = sql_fetch($count_sql);
    $total_count += $count_result['cnt'];
}
// 출력
echo "총 Review 수 : " . number_format($total_count);
---------------------------------------------------------
$board_list = ['bbs01', 'bbs02', 'bbs03', 'bbs04', 'bbs05']; // 지정된 게시판만 포함
$total_count = 0;
foreach ($board_list as $bo_table) {
    $table_name = 'g5_write_' . $bo_table;
    $count_sql = "SELECT COUNT(*) AS cnt FROM {$table_name}";
    $count_result = sql_fetch($count_sql);
    $total_count += $count_result['cnt'];
}
echo "총 Review 수 : " . number_format($total_count);
--------------------------------------------------------
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 12
© SIRSOFT
현재 페이지 제일 처음으로