공지사항 출력 순서 채택완료
공지사항으로 글을 등록하게 되면 글을 작성한 날짜 순서가 아닌 글 등록 순서대로 리스트되고 있는걸
등록순서가 아닌 날짜순서로 나오게하고싶습니다.
공지글을 수정했을시 수정된글을 맨 위로 올리고 싶습니다.
방법이없을까요?
bbs/list.php 파일
// 공지 처리 $arr_notice = explode(',', trim($board['bo_notice'])); if (!$stx) { $from_notice_idx = ($page - 1) * $page_rows; if($from_notice_idx < 0) $from_notice_idx = 0; $board_notice_count = count($arr_notice);
for ($k=0; $k<$board_notice_count; $k++) { if (trim($arr_notice[$k]) == '') continue;
$row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
if (!$row['wr_id']) continue;
// 분류일 때 if($sca) { if($row['ca_name'] != '공지' && $sca != $row['ca_name']) continue; }
$notice_array[] = $row['wr_id'];
if($k < $from_notice_idx) continue;
$list[$i] = get_list($row, $board, $board_skin_url, G5_IS_MOBILE ? $board['bo_mobile_subject_len'] : $board['bo_subject_len']); $list[$i]['is_notice'] = true; /*추가 시작*/ $notice_order .= " and wr_id != '$arr_notice[$k]'"; //[2008-02-03] 추가 /*추가 끝*/ $i++; $notice_count++;
if($notice_count >= $list_page_rows) break; } }
/*추가 시작*/ //분류선택시 전체페이지에서 공지사항의 갯수만큼 빼줌.[2008-02-03]//추가 if($min_spt) { $total_page = ceil($total_count / $board[bo_page_rows]); }else{ $total_page = ceil(($total_count - $bo_notics_cnt) / $board[bo_page_rows]); }
/*추가 끝*/ $total_page = ceil($total_count / $page_rows); // 전체 페이지 계산 $from_record = ($page - 1) * $page_rows; // 시작 열을 구함
// 공지글이 있으면 변수에 반영 if(!empty($notice_array)) { //$from_record -= count($notice_array);
if($from_record < 0) $from_record = 0;
//if($notice_count > 0) //$page_rows -= $notice_count;
if($page_rows < 0) $page_rows = $list_page_rows; }
// 관리자라면 CheckBox 보임 $is_checkbox = false; if ($is_admin) $is_checkbox = true;
// 정렬에 사용하는 QUERY_STRING $qstr2 = 'bo_table='.$bo_table.'&sop='.$sop; if($sca) $qstr2 .= '&sca='.urlencode($sca);
// 0 으로 나눌시 오류를 방지하기 위하여 값이 없으면 1 로 설정 $bo_gallery_cols = $board['bo_gallery_cols'] ? $board['bo_gallery_cols'] : 1; $td_width = (int)(100 / $bo_gallery_cols);
// 정렬 // 인덱스 필드가 아니면 정렬에 사용하지 않음 //if (!$sst || ($sst && !(strstr($sst, 'wr_id') || strstr($sst, "wr_datetime")))) { if (!$sst) { if ($board['bo_sort_field']) { $sst = $board['bo_sort_field']; } else { $sst = "wr_num, wr_reply"; $sod = ""; } } else { // 게시물 리스트의 정렬 대상 필드가 아니라면 공백으로 (nasca 님 09.06.16) // 리스트에서 다른 필드로 정렬을 하려면 아래의 코드에 해당 필드를 추가하세요. // $sst = preg_match("/^(wr_subject|wr_datetime|wr_hit|wr_good|wr_nogood)$/i", $sst) ? $sst : ""; $sst = preg_match("/^(wr_datetime|wr_hit|wr_good|wr_nogood|wr_comment|as_view|as_down|as_download|as_poll|as_update|wr_link1_hit|wr_link2_hit)$/i", $sst) ? $sst : ""; }
if(!$sst) $sst = "wr_num, wr_reply";
if ($sst) { $sql_order = " order by {$sql_apms_orderby} {$sst} {$sod} "; }
if ($sca || $stx) { $sql = " select distinct wr_parent from {$write_table} where {$sql_search} {$sql_order} limit {$from_record}, $page_rows "; } else { $sql = " select * from {$write_table} where wr_is_comment = 0 $notice_order /*$notice_order 추가*/ {$sql_apms_where} "; if(!$is_notice_list && $notice_count) $sql .= " and wr_id not in (".implode(', ', $arr_notice).") "; $sql .= " {$sql_order} limit {$from_record}, $page_rows "; }
위 부분을 수정해주면될것같은데 도움좀 부탁드립니다.
답변 4개
i값을 증가 시켜서 입니다 순서 변경후 i를 초기화 하시면 됩니다.
/******************************* $arr_notice 자료를 재정리합니다 ********************************/ $arr_noitce_array=array(); $arr_notice_cnt = count($arr_notice); if($arr_notice_cnt) { for($i=0;$i<$arr_notice_cnt;$i++){ $arr_notice_array[]=" wr_id='".$arr_notice[$i]."' "; } $arr_notice_sql= implode(" OR ", $arr_notice_array ); $sql2 = "select wr_id from {$write_table} where ( {$arr_notice_sql} ) order by wr_last desc"; $result2=sql_query($sql2); $i=0; while($row2=sql_fetch_array($result2)){ $arr_notice[$i]=$row2[wr_id]; $i++; } } //==================================
$i = 0; //이부분을 추가하세요
댓글을 작성하려면 로그인이 필요합니다.
onlymilk47님 좋은 자료 감사합니다~
덕서리님처럼 열람중 보이면
$i를 $j로 모두 바꾸어보세요,
전 바꾸니 잘됩니다^^
$arr_noitce_array=array(); $arr_notice_cnt = count($arr_notice); if($arr_notice_cnt) { for($j=0;$j<$arr_notice_cnt;$j++){ $arr_notice_array[]=" wr_id='".$arr_notice[$j]."' "; } $arr_notice_sql= implode(" OR ", $arr_notice_array ); $sql2 = "select wr_id from {$write_table} where ( {$arr_notice_sql} ) order by wr_datetime desc"; $result2=sql_query($sql2); $j=0; while($row2=sql_fetch_array($result2)){ $arr_notice[$j]=$row2[wr_id]; $j++; } }
댓글을 작성하려면 로그인이 필요합니다.
답변감사드립니다.
알려주신대로해봤는데
3개의 글중 2개를 공지로했을떄
글 2개가 상단으로 가면서 열람중으로나오면서 제목이 사라지네요..
![]()
뭐가 잘못된걸까요?
도움 부탁드립니다.
댓글을 작성하려면 로그인이 필요합니다.
상단부분 정렬에서
$arr_notice = explode(',', trim($board['bo_notice']));
/******************************* $arr_notice 자료를 재정리합니다 ********************************/ $arr_noitce_array=array(); $arr_notice_cnt = count($arr_notice); if($arr_notice_cnt) { for($i=0;$i<$arr_notice_cnt;$i++){ $arr_notice_array[]=" wr_id='".$arr_notice[$i]."' "; } $arr_notice_sql= implode(" OR ", $arr_notice_array ); $sql2 = "select wr_id from {$write_table} where ( {$arr_notice_sql} ) order by wr_last desc"; $result2=sql_query($sql2); $i=0; while($row2=sql_fetch_array($result2)){ $arr_notice[$i]=$row2[wr_id]; $i++; } } //==================================
if (!$stx) { $from_notice_idx = ($page - 1) * $page_rows; if($from_notice_idx < 0) $from_notice_idx = 0; $board_notice_count = count($arr_notice);
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인