전체게시판 조회해서 조회수로 베스트 뽑아내는건 어떻게 해야하나용.. 채택완료
http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=86485&sca=%C3%D6%BD%C5%B1%DB&sfl=wr_subject%7C%7Cwr_content&stx=%B4%F1%B1%DB&sop=and">http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=86485&sca=%C3%D6%BD%C5%B1%DB&sfl=wr_subject%7C%7Cwr_content&stx=%B4%F1%B1%DB&sop=and
여기 링크를 보아도 잘 모르겠고...
되지가 않아서 답답하네요... ㅠㅠㅠ
<?php
$board_sql = 'select bo_table from '. $g4['board_table'];
$board_query = sql_query($board_sql);
$board_list = '';
$tabAll = array();
$tabAll_limit = 7; //최대순위
//각 게시판 테이블명 뽑아내기
while( $board_fetch = sql_fetch_array($board_query) ) {
$board_select = 'select wr_subject as subject, wr_hit as rank from g4_write_'. $board_fetch['bo_table'] .' order by wr_hit desc limit '. $tabAll_limit;
$board_best_query = sql_query($board_select);
for( $i=0; $i<$tabAll_limit; $i++ ) {
$board_best = sql_fetch_array($board_best_query);
if( $tabAll[$i] == false ) {
$tabAll[$i] = $board_best['rank'];
break;
}
for($p=0; $p<=$limit; $p++) {
//배열에 있는 값보다 랭크가 클경우
if( $tabAll[$p] < $board_best['rank'] ) {
for($j=$p; $j<=$limit; $j++) {
$k = $j+1;
$tabAll[$k] = $tabAll[$j];
}
$tabAll[$p] = $board_best['rank'];
break;
}
}
}
}
이렇게 코딩해봤는데도....
잘안되구요..ㅠㅠ
도와주세요 ㅠ
답변 1개
전체게시판 조회해서 조회수로 베스트 뽑아내는건 어떻게 해야하나용..
전체 게시판을 일단 하나로!
몇버전인지 몰라서 5버전으로 테이블이름 적을께요...
</p><p>$sql1 = "select bo_table from g5_board";</p><p>$sql2 = "";</p><p>$count = 0;</p><p>while($row1 = sql_fetch($sql1)){</p><p style="margin-left: 40px;">if($count == 0){// 첫번째 셀렉트</p><p style="margin-left: 80px;"><span style="font-family: 돋움, Dotum, Helvetica, sans-serif; font-size: 12px; line-height: 18px;">$sql2 .= "select * from ".$row1[bo_table];</span></p><p style="margin-left: 80px;"><font face="돋움, Dotum, Helvetica, sans-serif"><span style="font-size: 12px; line-height: 18px;">$count++;</span></font></p><p style="margin-left: 40px;">}else{// 이후에 붙는 셀렉트</p><p style="margin-left: 80px;"><span style="font-family: 돋움, Dotum, Helvetica, sans-serif; font-size: 12px; line-height: 1.5;">$sql2 .= " union select * from ".$row1[bo_table];</span></p><p style="margin-left: 40px;"><span style="font-family: 돋움, Dotum, Helvetica, sans-serif; font-size: 12px; line-height: 1.5;">}</span></p><p>}</p><p>$sql2 .= "order by wr_hit desc limit 1";</p><p>$row2 = sql_fetch($sql2);</p><p>
일케하면 $row2에는 조회수가 제일 많은 게시글의 정보가 들어가있을꺼에요 ^^
끝...
답변에 대한 댓글 1개
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
일단 union all 을 활용해서 테이블 짜는건 성공했습니다.
그덕에 데이터는 뽑을 수 있게 되었는데요!!
이제 그 데이터에 링크를 걸어주어야되는데 링크를 못거네요 ㅋ.ㅋ
bo_table값을 가져와야하는데 이젠 이게 문제입니다. ㅠ
[code]
<?php
$board_sql = 'select bo_table from '. $g4['board_table'];
$board_query = sql_query($board_sql);
$board_column = 'wr_subject, wr_hit';
$tabAll_limit = 6; //최대순위
//각 게시판 테이블명 뽑아내기
while( $board_fetch = sql_fetch_array($board_query) ) {
$bo_table = $board_fetch['bo_table'];
if(!$tabAllBoard['query']) {
$tabAllBoard['query'] = '(select '. $board_column .' from g4_write_'. $bo_table .')';
} else {
$tabAllBoard['query'] .= ' union all (select '. $board_column .' from g4_write_'. $bo_table .')';
}
}
$tabAllQuery = 'select '. $board_column .' from ('. $tabAllBoard['query'] .') A order by wr_hit desc limit '. $tabAll_limit;
$tabAllResult = sql_query($tabAllQuery);
$i=1;
while( $tabAll = sql_fetch_array($tabAllResult) ) {
?>
<li class="h_icon0<?=$i++?>"><a href="<?=$g4['bbs_path']?>/board.php?bo_table="><?=$tabAll['wr_subject']?></a><?=$tabAll['wr_hit']?></li>
<?php
}
?>
[/code]