여러 테이블에 특정아이디가 작성한 건수를 확인하려면??? 채택완료
게시판 기본 포맷이 g5_write_테이블명입니다.
테이블을 QnA의 케이스에 따라 여러개 만들었는데요...
g5_write_qna01, g5_write_qna02,,,,, g5_write_qna05 에서
특정한 아이디가 작성한 건이 몇 건인지를 개별적으로는 쿼리를 하여 알 수 있는데요
select count(wr_id) AS count from g5_write_qna01 where mb_id = '${member['mb_id']}' and wr_is_comment = '0' ;
....
select count(wr_id) AS count from g5_write_qna05 where mb_id = '${member['mb_id']}' and wr_is_comment = '0' ;
한번에 count 몇건인지 알 수 있도록 쿼리를 할 수 없을까요?
건건이 5번 하고 더하기를 해서 확인하기 좀 번거롭네요...
답변 4개
</p><p>$sql = "</p><p>SELECT (
(
SELECT count( * ) cnt
FROM g5_write_qa1
WHERE mb_id = '{$id}'
AND wr_is_comment =0
) + (
SELECT count( * ) cnt
FROM g5_write_qa2
WHERE mb_id = '{$id}'
AND wr_is_comment =0
) + (
SELECT count( * ) cnt
FROM g5_write_qa3
WHERE mb_id = '{$id}'
AND wr_is_comment =0
)
)count </p><p>"; </p><p>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
대략 이런식으로 하면 되겠네요
</p><pre style="line-height: normal;">$sql = sql_query("select * from {$g5['board_table']}"); //db의 모든 게시판을 찾는다.
while($data = sql_fetch_array($sql)){
$row = sql_fetch("SELECT COUNT(*) AS cnt FROM g5_write_{$data[bo_table]} where mb_id = '{$member['mb_id']}' ");
//게시판 하나씩 해당 아이디의 글갯수를 구한다.
$board_total += $row['cnt']; //총갯수가 나올때마다 $board_total에 더한다.
}
echo $board_total; //총게시판의 해당 id의 게시글갯수 출력</pre><p>
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
g5_board_new에서 읽어오면 될 듯 하네요.
ex)
select count(*) from g5_board_new where bo_table in ('table1', 'table2') and mb_id='admin'
table1과 table2에 bo_table을 넣으면 될 겁니다.
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인