여러 게시판 대상으로 공지글만 모으다...... 정보
여러 게시판 대상으로 공지글만 모으다......본문
여러 게시판 대상으로 공지글만 모으다 말았습니다.
$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
댓글 5개
지금 쓸껀 아니지만 써먹어봐야겠네요 나중에 홈피 리뉴얼할때 ㅎㅎ
추천합니당+_+
<?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;
}
?>