여러게시판의 게시물 숫자 합계 자동출력 채택완료
예를들어서
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'];
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
</p>
<p>// 'bbs'로 시작하는 게시판 목록 가져오기
$sql = "SELECT bo_table FROM g5_board WHERE bo_table LIKE 'bbs%'";
$result = sql_query($sql);</p>
<p>$total_count = 0;</p>
<p>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'];
}</p>
<p>// 출력
echo "총 Review 수 : " . number_format($total_count);
---------------------------------------------------------</p>
<p>$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'];
}</p>
<p>echo "총 Review 수 : " . number_format($total_count);
--------------------------------------------------------</p>
<p>
댓글을 작성하려면 로그인이 필요합니다.
모든 게시물 수를 구한다면,
$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])."";
?>
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인