게시판마다 출력되는 갯수를 제한하려면 어떻게 해야 하나요? 정보
게시판마다 출력되는 갯수를 제한하려면 어떻게 해야 하나요?본문
아래는 스킨게시판에 있는 최신글 베스트를 뽑는 스킨입니다.
맨 밑쪽의 빨간 배경으로 된 usort_best1 함수를 실행시킨 후에,
게시판마다 출력되는 갯수를 특정 값으로 제한하고 싶습니다.
이것 저것 해 봤지만 초보인지라 잘 안되네요.
어떤 식으로 해야 한다.. 라는 힌트라도 좀 주십시오~
-----------------------------------------------------------------------------
<?
//전체게시판 또는 지정된 그룹에서 추천수,조회수,코멘트가 일정이상인 게시판중 베스트를 추려 출력한다.
//게시판명과는 관계가 없으므로 가능한 작은수의 게시판을 지정한다.
//작성 : freeimage.kr 김성대 2009-11-29
//사용 방법
//1. latest.skin.php 의 상단부분에서 추천수,조회수 등을 지정한다.
$추천수=5;
$조회수=50;
$코멘트=2;
$검색일=30;
if (!$rows) $rows=10;
if (!$subject_len) $subject_len=40;
$gr_id_지정=""; //특정 그룹을 지정할경우 공백으로 구별하여 나열
$gr_id_제외="gnu bujok adm help tax"; //특정 그룹을 제외할경우 공백으로 구별하여 나열
$bo_table_지정=""; //특정 게시판을 지정할경우 공백으로 구별하여 나열
$bo_table_제외=""; //특정 게시판을 제외할경우 공백으로 구별하여 나열
//1 가능한 게시판 읽기
if (!function_exists("parse_arr1")) {
function parse_arr1($str) {
$str=trim($str);
if (!$str||count($str)<1) return "";
$out="";
$arr=explode(" ",$str);
foreach($arr as $code) {
if ($out) $out.=",";
$out.="'$code'";
}
if ($out) return "($out) ";
return "";
}
}
$arr_board = array();
$bo_list_level=intval($member[mb_level]);if ($bo_list_level<=1) $bo_list_level=1;
$sql = "select * from $g4[board_table] where bo_list_level<=$bo_list_level and bo_use_search = '1' ";
if ($gr_id_지정) $sql.="and gr_id in ".parse_arr1($gr_id_지정);
if ($gr_id_제외) $sql.="and gr_id not in ".parse_arr1($gr_id_제외);
if ($bo_table_지정) $sql.="and bo_table in ".parse_arr1($bo_table_지정);
if ($bo_table_제외) $sql.="and bo_table not in ".parse_arr1($bo_table_제외);
$result = sql_query($sql);
$board_list="";
for ($i=0; $row=sql_fetch_array($result); $i++)
{
//var_dump($row);
$arr_board["{$row[bo_table]}"]=$row[bo_subject2]?$row[bo_subject2]:$row[bo_subject];
if ($board_list) $board_list.=",";
$board_list.="'$row[bo_table]'";
}
//secho $sql,$board_list;
// 2 해당되는 모든 글 가져오기
$sql_common = "from $g4[board_new_table] where 1 ";
if ($_GET[bo_table]) $sql_common.= "and bo_table='$_GET[bo_table]' ";
else $sql_common.= "and bo_table in ($board_list) ";
$sql_common.= "and wr_id = wr_parent "; //원글만 검색
//$sql_common .= "and a.wr_id <> a.wr_parent "; //코멘트만 검색하려면 이것
//if ($gr_id) $sql_common .= " and b.gr_id = '$gr_id' ";
$sql_common .= "and bn_datetime >= '".date("Y-m-d H:i:s",time()-$검색일*24*3600)."' "; //최근 30일기준
$sql_order = " order by bn_id desc ";
//$sql_order = " order by a.bn_datetime desc ";
$list = array();
$sql = " select *
$sql_common
$sql_order
limit 10000 "; //10000개까지 너무 많으면 메모리 속도 문제됨
$result = sql_query($sql);
//echo "$sql<BR>";
$i=0;
while($row=sql_fetch_array($result))
{
$tmp_write_table = $g4[write_prefix] . $row[bo_table];
$row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
if ($row2[wr_good]>=$추천수 or $row2[wr_hit]>=$조회수 or $row2[wr_comment]>=$코멘트) { //추천 5개 이상 또는 조회 50건 이상 또는 코멘트 2개이상
$row2[bo_table]=$row[bo_table];
$list[$i] = $row2;
$i++;
}
}
# 인기글 //점수 조건 hit+댓글*30+(추천-반대)*300 function usort_best1($a, $b) { return $b['wr_hit']+$b['wr_comment']*30+($b[wr_good]-$b[wr_nogood])*300 - ($a['wr_hit']+$a['wr_comment']*30+($a[wr_good]-$a[wr_nogood])*300); } usort($list, 'usort_best1'); |
?>
<style>
.list_comment3 {color:#404040;background-color:#f0f0f0;font-size:8pt;font-family:tahoma;font-weight:bold}
</style>
<? for ($i=0; $i<min($rows,count($list)); $i++) { ?>
<img src="<?=$latest_skin_path?>/img/<?=($i+1)?>.gif" border="0" align=absmiddle>
<a href='<?=$g4[bbs_path]?>/board.php?bo_table=<?=$list[$i][bo_table]?>&wr_id=<?=$list[$i][wr_id]?>'><?=cut_str($list[$i][wr_subject],$subject_len)?></a>
<? if ($list[$i][wr_comment]) echo "<sup><span class=list_comment3> {$list[$i][wr_comment]} </span></sup>"; ?>
<? //="H:{$list[$i][wr_hit]} Cmt: {$list[$i][wr_comment]} 추천: {$list[$i][wr_good]} 반대: {$list[$i][wr_nogood]} "?>
<BR>
<? } ?>
댓글 전체
하나의 게시판이 아니라 모든 게시물에 대한 베스트를 뽑고, 거기에서 게시판당 출력수를 제한하려는 거거든요...