2026, 새로운 도약을 시작합니다.

게시판 그룹 추출할때 날짜순으로 정렬이 궁금합니다. 채택완료

그룹별 추출을 날짜순으로 변경하고 싶습니다.
여기저기 검색해서 수정해 봤는데 도저히 안되서...질문드립니다.
쿼리쪽으로는 많이 부족해서 지식의 한계를 느껴서 올려봅니다. ㅠㅠ
고수님들 답변부탁드립니다!

// 최신글 추출
// $cache_time 캐시 갱신시간
function latest_group($skin_dir='', $gr_id, $rows=10, $subject_len=40, $cache_time=1, $options='')

{
    global $g5;

    if (!$skin_dir) $skin_dir = 'basic';

    if(preg_match('#^theme/(.+)$#', $skin_dir, $match)) {
        if (G5_IS_MOBILE) {
            $latest_skin_path = G5_THEME_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            if(!is_dir($latest_skin_path))
                $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        } else {
            $latest_skin_path = G5_THEME_PATH.'/'.G5_SKIN_DIR.'/latest/'.$match[1];
            $latest_skin_url = str_replace(G5_PATH, G5_URL, $latest_skin_path);
        }
        $skin_dir = $match[1];
    } else {
        if(G5_IS_MOBILE) {
            $latest_skin_path = G5_MOBILE_PATH.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_MOBILE_URL.'/'.G5_SKIN_DIR.'/latest/'.$skin_dir;
        } else {
            $latest_skin_path = G5_SKIN_PATH.'/latest/'.$skin_dir;
            $latest_skin_url  = G5_SKIN_URL.'/latest/'.$skin_dir;
        }
    }

    $cache_fwrite = false;
    if(G5_USE_CACHE) {
        $cache_file = G5_DATA_PATH."/cache/latest-group-{$gr_id}-{$skin_dir}-{$rows}-{$subject_len}.php";

        if(!file_exists($cache_file)) {
            $cache_fwrite = true;
        } else {
            if($cache_time > 0) {
                $filetime = filemtime($cache_file);
                if($filetime && $filetime < (G5_SERVER_TIME - 3600 * $cache_time)) {
                    @unlink($cache_file);
                    $cache_fwrite = true;
                }
            }

            if(!$cache_fwrite)
                include($cache_file);
        }
    }

    if(!G5_USE_CACHE || $cache_fwrite) {
        $list = array();
        $sql_common = " from {$g5['board_new_table']} a, {$g5['board_table']} b, {$g5['group_table']} c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = 1 ";
        $sql_common .= " and b.gr_id = '$gr_id' ";
        // $sql_common .= " and a.bo_table not in ('aaaa', 'bbbb') ";
        $sql_common .= " and a.wr_id = a.wr_parent ";
        $sql_order = " order by a.bn_id desc ";
        $sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id {$sql_common} {$sql_order} limit 0, {$rows}";
  $result = sql_query($sql);

  for ($i=0; $row=sql_fetch_array($result); $i++) {

   $sql = " select * from {$g5['board_table']} where bo_table = '{$row['bo_table']}' ";
   $board = sql_fetch($sql);
   $gr_subject = $row['gr_subject'];

   $tmp_write_table = $g5['write_prefix'] . $row['bo_table'];
   $row2 = sql_fetch(" select * from {$tmp_write_table} where wr_id = '{$row['wr_id']}' ");

   $list[$i] = $row2;
   $list[$i] = get_list($row2, $board, $latest_skin_url, $subject_len);
   $list[$i]['bo_subject'] = $row['bo_subject'];
   $list[$i]['bo_table'] = $row['bo_table'];
  }

        if($cache_fwrite) {
            $handle = fopen($cache_file, 'w');
            $cache_content = "<?php\nif (!defined('_GNUBOARD_')) exit;\n\$gr_subject='".$gr_subject."';\n\$list=".var_export($list, true)."?>";
            fwrite($handle, $cache_content);
            fclose($handle);
        }
    }

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

    return $content;
}

답변 1개

채택된 답변
+20 포인트

 $sql_order = " order by a.bn_id desc "; <-- 이게 최신글 등록순으로(최신글이 먼저 나오게) 하는

부분인데 이것말고 어떤 날짜 순을 말하는가요?

로그인 후 평가할 수 있습니다

답변에 대한 댓글 4개

답변 감사합니다~!
등록순을 날짜순으로 정렬되도록 하고싶습니다.
그룹게시판 아닐때는 아래처럼하면 됬었는데..
order by wr_datetime desc
그룹게시판은 안먹혀서요.
이해가 안되네요
bn_id 값이 등록순 즉 날짜 순이죠
시간적으로 뒤에 등록되면 bn_id 값이 크게 되는데....
굳이 날짜를 지정해서 하려면 a.bn_datetime desc 입니다
말씀하신대로 " order by a.bn_datetime desc "적용은 해봤는데
캐시삭제해도 순서는 변하지는 않네요ㅠ_ㅜ
게시물은 출력되는거보니깐 알려주신대로 적용하는건 맞는거같습니다.
(잘못넣으면 게시물자체가 안뜨더라고요)
제가 다른곳에서 소스 적용을 잘못했을수도...

게시판에서 날짜 수정으로 순서를 변경할 수 있게 해놨는데 메인추출도 같이 적용 해야 될 것 같아서요.

답변 감사합니다^^
게시판에서 날짜 수정가능하게 해놨고 그 날짜순으로 출력한다는 것이군요.
처음부터 질문을 그렇게 해야죠
그렇게는 안됩니다

g5_board_new테이블에 등록된 게시물을 날짜순으로 가져와서 실제 게시판에서 해당 게시물을
추출하는 것인데 사용 게시판에서 등록 일자를 변경하면 적용이 안될 수 밖에 없습니다

방법은 게시판에서 등록일자를 변경할때 g5_board_new테이블에서도 등록일자가 변경 되도록
코드를 넣어야 됩니다

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

답변을 작성하려면 로그인이 필요합니다.

로그인
🐛 버그신고