리스트 정렬의 방법 > 그누4 질문답변

그누4 질문답변

그누보드4 관련 질문은 QA 로 이전됩니다. QA 그누보드4 바로가기
기존 게시물은 열람만 가능합니다.

리스트 정렬의 방법 정보

리스트 정렬의 방법

본문

제가 연혁게시판 스킨을 만들었는데...
연혁게시판이기 때문에 자동으로 날짜별 정렬을 하고 싶습니다.

*꼼수로 제목에 날짜를 입력하고 게시판설정 화면에서 제목순 정렬 옵션을 주면
되는데... 이 방법은 스킨을 바꾸는 등의 범용성이 떨어져서...

날짜는 시작일 wr_1, 종료일 wr_2를 사용했습니다.

좋은 방법을 알려주세요.


스킨 : http://sir.co.kr/bbs/board.php?bo_table=g4_skin&wr_id=80432&page=2


-------아래는 list.skin.php입니다.-----
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
include_once "$board_skin_path/skin.lib.php";


// 제목이 두줄로 표시되는 경우 이 코드를 사용해 보세요.
// <nobr style='display:block; overflow:hidden; width:000px;'>제목</nobr>

$max = 100; // 이미지의 가로세로(긴쪽)의 최대치.

$resol = 100 ; // 생성되는 썸네일의 JPG압축률.(퍼센트%)

function smaller( $W, $H ) {
global $max, $thum_W, $thum_H ;

if ( $W > $H ) { //가로형일 경우.
$thum_W = $max ;
$thum_H = ceil( $H * ( $max / $W ) );
}
if ( $W < $H ) { //세로형일 경우.
$thum_H = $max ;
$thum_W = ceil( $W * ( $max / $H ) );
}
if ( $W == $H ) { //정사각형일 경우.
$thum_W = ceil( $max * 0.8 );
$thum_H = ceil( $max * 0.8 );
}
return $thum_W ;
return $thum_H ;
}


function maker( $thum_W, $thum_H ) {
global $thum, $resol, $ori, $ori_info ;

//$newImg = ImageCreate($thum_W,$thum_H); // GD라이브러리 2.0 (이하일 경우)
$newImg = ImageCreateTrueColor($thum_W,$thum_H); // GD라이브러리 2.0 전용함수

if($ori_info[2]=="2") $origImg=ImageCreateFromjpeg($ori);
if($ori_info[2]=="3") $origImg=ImageCreateFrompng($ori);

//ImageCopyResized($newImg,$origImg,0,0,0,0,$thum_W,$thum_H,ImageSX($origImg),ImageSY($origImg));
imageCopyResampled($newImg,$origImg,0,0,0,0,$thum_W,$thum_H,ImageSX($origImg),ImageSY($origImg));

Imagejpeg($newImg, $thum, $resol );

@chmod($thum,0707);
ImageDestroy($newImg);
ImageDestroy($origImg);

return $thum ;
}
// 선택옵션으로 인해 셀합치기가 가변적으로 변함
$colspan = 9;
if ($is_category) $colspan++;
if ($is_checkbox) $colspan++;
if ($is_good) $colspan++;
if ($is_nogood) $colspan++;

if ($is_category) {
    $nc_category_location  = "./board.php?bo_table=$bo_table&sca=$sca&sfl=wr_10&stx=";
    $nc_category_option    = get_nc_category_option($bo_table, $sca);
}
?>

<style type="text/css">
<!--
.w_fixed { table-layout:fixed; }
.w_font  { font-family:돋움; font-size:8pt; color:#777777; }
.w_title { font-family:굴림; font-size:9pt; color:#666666; }
.w_list { font-family:굴림; font-size:9pt; color:#777777; }
.w_notice { font-family:돋움; font-size:9pt; color:#2C88B9; }
.w_padding { PADDING-LEFT: 15px; PADDING-BOTTOM: 5px; PADDING-TOP: 5px; }
.w_padding2 { PADDING-LEFT: 15px; PADDING-TOP: 5px; }
.w_text  { BORDER: #D3D3D3 1px solid; HEIGHT: 18px; BACKGROUND-COLOR: #ffffff; }
.w_textarea  { BORDER: #D3D3D3 1px solid; BACKGROUND-COLOR: #ffffff; WIDTH: 100%; WORD-BREAK: break-all; }
.w_message  { font-family:돋움; font-size:9pt; color:#4B4B4B; }
.w_norobot  { font-family:돋움; font-size:9pt; color:#BB4681; }
-->
</style>


<br />
<? $lists = array();
for ($i=0; $i<count($list); $i++) {
$lists[$i] = $list[$i];
}
?>

<table width="<?=$width?>" align="center" cellpadding="0" cellspcing="0"><tr><td>
<table width="100%"><tr><td align="right">    <? if ($admin_href) { ?><a href="<?=$admin_href?>"><img src="<?=$board_skin_path?>/img/admin_button.gif" title="관리자" width="63" height="22" border="0" align="absmiddle"></a><? } ?></td></tr></table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="center">
<?php
    $arr = explode("|", $board[bo_category_list]);
    $arr1  = explode("|", $board[bo_10]);
$str = "";
    for ($i=0; $i<count($arr); $i++)
        if (trim($arr[$i])){
            if($arr[$i]==$sca){
    $key    = array_search($sca, $arr);
    $cate  = explode("^", $arr1[$key]);
    $subca1 = $cate[0];
$str .= "
    <td width='3'><img src='$board_skin_path/img/tab1_on_left.gif' width='3' height='26'></td>
    <td background='$board_skin_path/img/tab1_on_bg.gif' style='padding:5 15 0 15' nowrap><a href='$category_location$arr[$i]&sfl=wr_10&stx=$subca1&nca=$subca1'><font face='돋움' style='font-size:11px;font-weight:bold;color:#FF7904'>$arr[$i]</font></a></td>
    <td width='3'><img src='$board_skin_path/img/tab1_on_right.gif' width='3' height='26'></td>
<td><img src='$board_skin_path/img/dot_2.gif' width='2'></td>

";
}else{
    $key    = array_search($arr[$i], $arr);
    $cate  = explode("^", $arr1[$key]);
    $subca1=$cate[0];
$str .= "
    <td width='3'><img src='$board_skin_path/img/tab1_off_left.gif' width='3' height='26'></td>
    <td background='$board_skin_path/img/tab1_off_bg.gif' style='padding:5 15 0 15' nowrap><a href='$category_location$arr[$i]&sfl=wr_10&stx=$subca1&nca=$subca1'><font face='돋움' style='font-size:11px;color:#474747'>$arr[$i]</font></a></td>
    <td width='3'><img src='$board_skin_path/img/tab1_off_right.gif' width='3' height='26'></td>
<td><img src='$board_skin_path/img/dot_2.gif' width='2'></td>
";
}
}
echo $str;
echo "<td width='100%' height='26'  repeat-x bottom'></td>";
?>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr><td height="1" bgcolor="#cccccc"></td>
    <tr><td height="10"></td>
</tr></table>

<table width="100%" border="0" cellspacing="0" cellpadding="5">
  <tr>
    <td width="100" height="2" bgcolor="#0DCEA3"></td>
    <td bgcolor="#0DCEA3"></td>
<? if ($member[mb_level] == "10" || $is_admin) { ?>
    <td bgcolor="#0DCEA3"></td>
    <? } ?>
  </tr>
  <? for ($i=0; $i<count($list); $i++) { ?>
  <tr>
    <td width="100" align="center" valign="middle" bgcolor="#F8F8F8"><table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td><div align="center">
          <?=$list[$i][wr_1]?>
        </div></td>
        <? if ($list[$i][wr_2]) { ?>
        <td width="20"><div align="center">~</div></td>
        <td><div align="center">
          <?=$list[$i][wr_2]?>
        </div></td>
        <? } ?>
      </tr>
    </table>
        <? if ($list[$i][wr_5]) { ?>
        <font class="w_font">
        <?=$list[$i][wr_3]?>
        </font>
        <? } ?>    </td>

    <td valign="middle"><!------본문시작--------->
        <table width="100%" border="0" cellspacing="0" cellpadding="3">
          <tr>
            <td><a href="<?=$list[$i][ca_name_href]?>&amp;sfl=wr_10&amp;stx=<?=$list[$i][wr_10]?>&amp;nca=<?=$list[$i][wr_10]?>"><font class="w_font">
              <?=$list[$i][wr_10]?>
              </font></a> <strong>
             
  <? echo $nobr_begin;
        echo $list[$i][reply];
        echo $list[$i][icon_reply];
      //** echo "<a href='{$list[$i][href]}'>";
        if ($list[$i][is_notice])
            echo "<font class=w_notice><strong>{$list[$i][subject]}</strong></font>";
        else
            echo "<font class=w_list>{$list[$i][subject]}</font>";
      //** echo "</a>";

      //** if ($list[$i][comment_cnt])
      //**    echo " <a href=\"javascript:{$list[$i][comment_href]}\"><span style=\"font-family:돋움; font-size:8pt; color:#9A9A9A\">{$list[$i][comment_cnt]}</a>";

        // if ($list[$i]['link']['count']) { echo "[{$list[$i]['link']['count']}]"; }
        // if ($list[$i]['file']['count']) { echo "<{$list[$i]['file']['count']}>"; }

        echo " " . $list[$i][icon_new];
        echo $nobr_end;
        ?></strong><? if ($list[$i][wr_4]) { ?> (<?=$list[$i][wr_4]?>) <? } ?></td>
          </tr>
          <? if ($list[$i][wr_5]) { ?>
          <tr>
            <td><font class="w_font"><strong><?=$board[bo_5] ?>:&nbsp;</strong>
                  <?=$list[$i][wr_5]?>
              &nbsp;&nbsp;&nbsp;<strong>
              <?=$board[bo_6] ?>
              :</strong>
              <?=$list[$i][wr_6]?>
            </font></td>
          </tr>
          <? } ?>
          <? if ($list[$i][wr_7]) { ?>
          <tr>
            <td><font class="w_font"><strong>
              <?=$board[bo_7] ?>
              :&nbsp;</strong>
                  <?=$list[$i][wr_7]?>
              &nbsp;&nbsp;&nbsp;<strong>
              <?=$board[bo_8] ?>
              :</strong>
              <?=$list[$i][wr_8]?>
            </font></td>
          </tr>
          <? } ?>
          <? if ($list[$i][wr_9]) { ?>
          <tr>
            <td><font class="w_font"><strong>
              <?=$board[bo_9] ?>
              :&nbsp;</strong>
                  <?=$list[$i][wr_9]?>
            </font></td>
          </tr>
          <? } ?>
          <? if ($list[$i][wr_9]) { ?>
          <tr>
            <td><font class="w_font"><strong>
              <?=$board[bo_9] ?>
              :&nbsp;</strong>
                  <?=$list[$i][wr_9]?>
            </font></td>
          </tr>
          <? } ?>
          <? if ($list[$i][wr_content]) { ?>
          <tr>
            <td><font class="w_font">
                  <?=$list[$i][wr_content]?>
            </font></td>
          </tr>
          <? } ?>  
        </table>
      <!------본문끝----------->
        <!----본문 이미지 부분 시작------>
        <table border="0" cellspacing="0" cellpadding="0" align="right">
          <? // 이미지 처리부분
##################################################################################################
$image = urlencode($list[$i][file][0][file]); // 첫번째 파일이 이미지라면
if ($image) {
if (preg_match("/\.(gif|jpg|png)$/i", $image) && file_exists("$g4[path]/data/file/$bo_table/$image")) {
$ori = "$g4[path]/data/file/$bo_table/$image"; //[필수](URL) "./img/Test.gif"
}

$ext = strtolower(substr(strrchr($ori,"."), 1)); //확장자

if ( $ext=="gif"||$ext=="jpg"||$ext=="jpeg"||$ext=="png"||$ext=="bmp"||$ext=="tif"||$ext=="tiff")
$ori_info=getimagesize($ori);
else
$ori_info="";

//===== 원파일이 [ 2JPG, 2JPEG, 3PNG ] 경우
if ( $ori_info[2]=="2" || $ori_info[2]=="3" ) {
$thum = $ori.".Thum" ;

if ( file_exists($thum) ) { // Thumbnail [O] 경우
$thum_info = getimagesize ($thum);
$thum_W = $thum_info[0] ;
$thum_H = $thum_info[1] ;
}
else { // Thumbnail [X] 경우
if ( smaller( $ori_info[0], $ori_info[1] ) ) {
maker( $thum_W, $thum_H );
}
}
}

//===== 원파일이 [ 1GIF,6BMP,7TIF ] 경우
else if ( $ori_info[2]=="1" || $ori_info[2]=="6" || $ori_info[2]=="7" ) {
if ( smaller( $ori_info[0], $ori_info[1] ) ) { $thum = $ori ; }
}


##################################################################################################
?>
          <tr>
            <td><img src='<?=$thum?>' alt='<?=$list[$i][wr_subject]?>' border="0" align="absmiddle" /> </td>
          </tr>
          <? }?>
        </table>
      <!----본문 이미지 끝--->    </td>
<? if ($member[mb_level] == "10" || $is_admin) { ?>
          <td valign="middle"><a href="<?=$write_href?>&w=u&wr_id=<?=$list[$i][wr_id]?>&page=<?=$page?>">E</a></td>
          <? } ?>
  </tr>
  <tr>
    <td width="100" height="1" bgcolor="#E1E1E1"></td>
    <td bgcolor="#E1E1E1"></td>
<? if ($member[mb_level] == "10" || $is_admin) { ?>
    <td height="1" bgcolor="#E1E1E1"></td> <? } ?>
  </tr>
<? } ?>
  <tr>
    <td width="100" height="1" bgcolor="#E1E1E1"></td>
    <td bgcolor="#E1E1E1"></td>
<? if ($member[mb_level] == "10" || $is_admin) { ?>
    <td height="1" bgcolor="#E1E1E1"></td> <? } ?>
  </tr>
</table>
<!-- 게시물 리스트 끝 -->
<!-- 페이지 표시 시작 -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
    <td height="37" align="center" valign="middle" background="<?=$board_skin_path?>/img/number_line.gif">
        <table width="500" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td width="100%" align="center">
                <? if ($prev_part_href) { echo "<a href='$prev_part_href'><img src='$board_skin_path/img/btn_search_prev.gif' width=50 height=20 border=0 align=absmiddle title='이전검색'></a>"; } ?>
                <?
                // 기본으로 넘어오는 페이지를 아래와 같이 변환하여 이미지로도 출력할 수 있습니다.
                //echo $write_pages;
                $write_pages = str_replace("처음", "<img src='$board_skin_path/img/begin.gif' border='0' align='absmiddle' title='처음'>", $write_pages);
                $write_pages = str_replace("이전", "<img src='$board_skin_path/img/prev.gif' border='0' align='absmiddle' title='이전'>", $write_pages);
                $write_pages = str_replace("다음", "<img src='$board_skin_path/img/next.gif' border='0' align='absmiddle' title='다음'>", $write_pages);
                $write_pages = str_replace("맨끝", "<img src='$board_skin_path/img/end.gif' border='0' align='absmiddle' title='맨끝'>", $write_pages);
                $write_pages = preg_replace("/<span>([0-9]*)<\/span>/", "<font style=\"font-family:돋움; font-size:9pt; color:#797979\">$1</font>", $write_pages);
                $write_pages = preg_replace("/<b>([0-9]*)<\/b>/", "<font style=\"font-family:돋움; font-size:9pt; color:orange;\">$1</font>", $write_pages);
                ?>
                <strong><?=$write_pages?></strong>
                <? if ($next_part_href) { echo "<a href='$next_part_href'><img src='$board_skin_path/img/btn_search_next.gif' width=50 height=20 border=0 align=absmiddle title='다음검색'></a>"; } ?>            </td>
        </tr>
        </table></td>
</tr>
</table>
<!-- 페이지 표시 끝 -->

<!-- 여백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="10"></td></tr></table>
<!-- 글쓰기 및 검색폼 -->
<table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr align="left" valign="middle">
        <td width="50%" height="40">
            <? if ($list_href) { ?><a href="<?=$list_href?>"><img src="<?=$board_skin_path?>/img/btn_list.gif" border="0" align="absmiddle"></a><? } ?>
            <? if ($write_href) { ?><a href="<?=$write_href?>"><img src="<?=$board_skin_path?>/img/btn_write.gif" border="0" align="absmiddle"></a><? } ?>
            <? if ($is_checkbox) { ?>
                <a href="javascript:select_copy('copy');"><img src="<?=$board_skin_path?>/img/btn_select_copy.gif" border="0" align="absmiddle"></a>
                <a href="javascript:select_copy('move');"><img src="<?=$board_skin_path?>/img/btn_select_move.gif" border="0" align="absmiddle"></a>
            <? } ?>        </td>
        <form name=fsearch method=get>
        <input type=hidden name=bo_table value="<?=$bo_table?>">
        <input type=hidden name=sca      value="<?=$sca?>">
        <td width="50%" align="right">
            <!-----
            <select name=sfl>
                <!-- DB에 상당한 부하가 걸리므로 사용을 추천하지 않음 <option value='wr_subject+wr_content+wc_content'>제목+내용+코멘트</option>
                <option value='wr_subject'>행사명</option>
                <option value='wr_content'>내용</option>
                <option value='wr_5'><?=$board[bo_5]?></option>
                <option value='wr_6'><?=$board[bo_6] ?></option>
                <option value='wr_name'>이름</option>
              -->
                <!-- 코멘트도 같이 검색할 경우에 사용합니다. (속도가 느려짐)
                <option value='b.wc_content'>코멘트</option>
                <option value='a.mb_id+b.mb_id'>회원아이디2</option>
                <option value='a.wr_name+b.wc_name'>이름2</option> -->
            <!---- 
            </select>
            <INPUT maxLength=15 size=10 name=stx itemname="검색어" required value="<?=$stx?>" style="ime-mode:active">
            <SELECT name=sop>
                <OPTION value=and>And</OPTION>
                <OPTION value=or>Or</OPTION>
            </SELECT>       
            ---->
            </td>
        <td width="10%" align="center">
        <!------
        <INPUT type=image src="<?=$board_skin_path?>/img/search_btn.gif" border=0>
        ------>
       
        </td>
        </form>
    </tr>
</table>
<!-- 글쓰기 및 검색폼 끝-->

</td></tr></table>


<blockquote>
  <blockquote>
    <p>
      <? if ($is_checkbox) { ?>
    </p>
    <p>
      <? } ?>
      <!-- 게시판 목록 끝 -->
    </p>
  </blockquote>
</blockquote>
<script language="JavaScript">
function all_checked(sw)
{
    var f = document.fboardlist;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]")
            f.elements[i].checked = sw;
    }
}

function check_confirm(str)
{
    var f = document.fboardlist;
    var chk_count = 0;

    for (var i=0; i<f.length; i++) {
        if (f.elements[i].name == "chk_wr_id[]" && f.elements[i].checked)
            chk_count++;
    }

    if (!chk_count) {
        alert(str + "할 게시물을 하나 이상 선택하세요.");
        return false;
    }
    return true;
}

// 선택한 게시물 삭제
function select_delete()
{
    var f = document.fboardlist;

    str = "삭제";
    if (!check_confirm(str))
        return;

    if (!confirm("선택한 게시물을 정말 "+str+" 하시겠습니까?\n\n한번 "+str+"한 자료는 복구할 수 없습니다"))
        return;

    f.action = "./delete_all.php";
    f.submit();
}

// 선택한 게시물 복사 및 이동
function select_copy(sw)
{
    var f = document.fboardlist;

    if (sw == "copy")
        str = "복사";
    else
        str = "이동";
                     
    if (!check_confirm(str))
        return;

    var sub_win = window.open("", "move", "left=50, top=50, width=396, height=550, scrollbars=1");

    f.sw.value = sw;
    f.target = "move";
    f.action = "./move.php";
    f.submit();
}
  </script>

댓글 전체

방법은 이렇습니다...
해당게시판의 여분필드 7번(board[bo_7])과 8번(board[bo_8])을 이용합니다..
bbs/list.php을 보면
if (!$sst)
{
    if ($board[bo_sort_field])
        $sst = $board[bo_sort_field];
    else
        $sst  = "wr_num, wr_reply";
    $sod = "";
}
$sql_order = " order by $sst $sod ";

이 부분이 있습니다..이 부분을

if (!$sst)
{
    if ($board[bo_sort_field])
        $sst = $board[bo_sort_field];
    else if($board[bo_7])
        $sst = "$board[bo_7]";
    else
        $sst  = "wr_num, wr_reply";
    $sod = "";
}
$sql_order = " order by $sst $sod $board[bo_8]";

이렇게 수정하시고

예를들어 wr_1순으로 asc 즉 올림차순(작은값부터출력)으로 한다면

해당게시판관리자의 여분필드 7에 wr_1을 입력하고 여분필드 8번에는 asc를 입력하면 됩니다..

또 wr_1순으로 desc 즉 내림차순(높은값부터출력)이라면 여분필드 7에 wr_1,여분필드8번에는 desc를 입력하면 됩니다..

두군데다 아무것도 입력안하면 기본형식으로 출력되겠지요,,
감사합니다.
list.php를 손대야 하니...
좀 고민이 되네요.
원본을 손대지 않는게 가장 좋을텐데...

여하튼 문제가 해결되서 속이 시원합니다....
원본에 손을 안대는게 가장 좋겠지요..

고민을 해보아도...

두개 중에 하나를 손을 대야하는 듯합니다...
 
adm/board_form.php

혹은

bbs/list.php
전체 23 |RSS
그누4 질문답변 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT