테스트 사이트 - 개발 중인 베타 버전입니다

여러 게시판 대상으로 공지글만 모으다......

여러 게시판 대상으로 공지글만 모으다 말았습니다.

$rows에서 지정된 수가 차면 loop를 멈춥니다.
순서 지정 기능 없습니다.

이 부분은

http://sir.co.kr/bbs/board.php?bo_table=g4_tiptech&wr_id=15413&page=2

참고하세요.


2008.06.02 코드 일부 수정:
    while( $row= sql_fetch_array( $notice_res)) {
        $this_notice= trim($row['bo_notice']);
        if( empty( $this_notice)) continue;
        $notice_wr_id_cond[]= implode( ',', split("\n", $this_notice));
        $notice_bo_tables[]= $row['bo_table'];
    }


mysql은 union이 지원되어야 합니다.
제목과 첨부 파일을 가져옵니다. 필요한 것이 있으면 select에서 항목 추가해 주세요.
테스트 안 해 봤습니다. 양해 바랍니다.
지금 작업하는 mysql 버젼이 3점대네요.

사용법은 일반 latest()와 비슷합니다.


for( sql_fetch_array())에서 버그 수정
get_list( $board 변수 추가)

<?php echo latest_notice( 'basic', array( 'a','b','c'), 10, 50); ?>


lib/latest_notice.php
<?php
if (!defined('_GNUBOARD_')) exit;

// 최신글 추출
function quoting(&$item1, $key) { $item1 = "'$item1'"; }
function latest_notice($skin_dir="", $bo_tables, $rows=10, $subject_len=40, $options="") {

    global $g4;

    if ($skin_dir)
        $latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
    else
        $latest_skin_path = "$g4[path]/skin/latest/basic";

    if( !is_array( $bo_tables)) return 'A second parameter error:bo_tables should be an array.';

    array_walk( $bo_tables , 'quoting');
    $bo_tables_cond= implode(',', $bo_tables);
    $notice_res= sql_query( "select bo_table, bo_notice from {$g4['board_table']} where bo_table in ( $bo_tables_cond ) " );

    $notice_wr_id_cond=array();
    $notice_bo_tables=array();

    while( $row= sql_fetch_array( $notice_res)) {
        $this_notice= trim($row['bo_notice']);
        if( empty( $this_notice)) continue;
        $notice_wr_id_cond[]= implode( ',', split("\n", $this_notice));
        $notice_bo_tables[]= $row['bo_table'];
    }

    $sqls= array();

    foreach( $notice_bo_tables as $idx => $notice_bo_table) {
        $sqls[]= " select wr_id , wr_subject from {$g4['write_prefix']}$notice_bo_table where wr_id in ( {$notice_wr_id_cond[$idx]} )";
    }

    $list = array();

    $result = sql_query( implode( ' union all ', $sqls));
    for ($i=0; ($row = sql_fetch_array($result)) && $i < $rows; $i++)
        $list[$i] = get_list($row, array( 'bo_table'=>$notice_bo_table), $latest_skin_path, $subject_len);

    ob_start();
    include "$latest_skin_path/latest.skin.php";
    $content = ob_get_contents();
    ob_end_clean();

    return $content;
}
?>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 5개

헐 대단하십니다 +_+
지금 쓸껀 아니지만 써먹어봐야겠네요 나중에 홈피 리뉴얼할때 ㅎㅎ
추천합니당+_+
테스트 부탁합니다. 감사합니다.
이번 것은 mysql v3.x 지원하는 것으로 바꾸었습니다.


<?php
if (!defined('_GNUBOARD_')) exit;

// 최신글 추출
function quoting(&$item1, $key) { $item1 = "'$item1'"; }
function latest_notice($skin_dir="", $bo_tables, $rows=10, $subject_len=40, $options="") {

global $g4;

if ($skin_dir)
$latest_skin_path = "$g4[path]/skin/latest/$skin_dir";
else
$latest_skin_path = "$g4[path]/skin/latest/basic";

if( !is_array( $bo_tables)) return 'A second parameter error:bo_tables should be an array.';

array_walk( $bo_tables , 'quoting');
$bo_tables_cond= implode(',', $bo_tables);
$notice_res= sql_query( "select bo_table, bo_notice from {$g4['board_table']} where bo_table in ( $bo_tables_cond ) " );

$notice_wr_id_cond=array();
$notice_bo_tables=array();

while( $row= sql_fetch_array( $notice_res)) {
$this_notice= trim($row['bo_notice']);
if( empty( $this_notice)) continue;
$notice_wr_id_cond[]= implode( ',', split("\n", $this_notice));
$notice_bo_tables[]= $row['bo_table'];
}

$list = array();
$i=0;
foreach( $notice_bo_tables as $idx => $notice_bo_table) {
$sql= " select wr_id, wr_subject from {$g4['write_prefix']}$notice_bo_table where wr_id in ( {$notice_wr_id_cond[$idx]} )";

for( $result= sql_query( $sql) ; ($row = sql_fetch_array($result)) && $i < $rows; $i++) {
$list[$i] = get_list($row, array('bo_table'=>$notice_bo_table), $latest_skin_path, $subject_len);
}
}
ob_start();
include "$latest_skin_path/latest.skin.php";
$content = ob_get_contents();
ob_end_clean();

return $content;
}
?>
어떻게 불러오나요?
와.. 보물과도 같은 소스 입니다. 감사합니다. ^^

게시판 목록

그누4 팁자료실

그누보드4와 관련된 팁을 여러분들과 함께 공유하세요.
나누면 즐거움이 커집니다.
글쓰기
🐛 버그신고