제

게시판 특정 컬럼조건 만족시 노출 (관리자 수락 후 노출)

· 2021-07-06 (화) 23:17:51 · 5677 · 5

게시물 작성 후 바로 노출되지 않고 관리자가 수락 후 노출되어야 하는 경우가 있습니다.

 

아래 코드와 같이 처리하시면 됩니다.

(관리자가 수락하는 코드는 포함되어있지 않습니다. 게시판 노출시 특정 컬럼조건을 만족하는 게시물만 쿼리하는 코드립니다.)

 

(아래 코드는 기존 컬럼(ex.wr_10)이 아닌 새로 생성한 컬럼(row_show)으로 조회합니다.

DB 해당 게시판 table에 노출여부 컬럼을 아래와 같이 생성하시거나

alter table g5_write_chk_and_show add row_show tinyint(1) 

혹은 기존 컬럼으로 조회 (where wr_10 = 1) 등으로 변경하시면 됩니다.)

 

/bbs/list.php

 

if ($sca || $stx || $stx === '0') {     //검색이면
    $is_search_bbs = true;      //검색구분변수 true 지정
    $sql_search = get_sql_search($sca, $sfl, $stx, $sop);

    // 가장 작은 번호를 얻어서 변수에 저장 (하단의 페이징에서 사용)
    $sql = " select MIN(wr_num) as min_wr_num from {$write_table} ";
    $row = sql_fetch($sql);
    $min_spt = (int)$row['min_wr_num'];

    if (!$spt) $spt = $min_spt;

    $sql_search .= " and (wr_num between {$spt} and ({$spt} + {$config['cf_search_part']})) ";

    //#조건노출
    if ($bo_table=="테이블명" && !$is_admin) {
        $sql_search .= " and row_show = 1 ";
    }


    // 원글만 얻는다. (코멘트의 내용도 검색하기 위함)
    // 라엘님 제안 코드로 대체 http://sir.kr/g5_bug/2922
    $sql = " SELECT COUNT(DISTINCT `wr_parent`) AS `cnt` FROM {$write_table} WHERE {$sql_search} ";
    $row = sql_fetch($sql);
    $total_count = $row['cnt'];
    /*
    $sql = " select distinct wr_parent from {$write_table} where {$sql_search} ";
    $result = sql_query($sql);
    $total_count = sql_num_rows($result);
    */
} else {

    //#조건노출
    if ($bo_table=="테이블명" && !$is_admin) {
        $sql_search = " row_show = 1 ";
        $sql = " SELECT COUNT(DISTINCT `wr_parent`) AS `cnt` FROM {$write_table} WHERE {$sql_search} ";
        $row = sql_fetch($sql);
        $total_count = $row['cnt'];
    }else{
        $sql_search = "";
        $total_count = $board['bo_count_write'];
    }


}

 

===============================

 

// 공지 처리
if (!$is_search_bbs) {
    $arr_notice = explode(',', trim($board['bo_notice']));
    $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;

        //#조건노출
        if ($bo_table=="테이블명" && !$is_admin) {
            $sql_search = " and row_show = 1 ";
            $row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' {$sql_search}");
        }else{
            $row = sql_fetch(" select * from {$write_table} where wr_id = '{$arr_notice[$k]}' ");
        }

 

================================

 

if ($is_search_bbs) {
    $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 ";


    //#조건노출
    if ($bo_table=="테이블명" && !$is_admin) {
        $sql_search = " and row_show = 1 ";
        $sql .= $sql_search;
    }

    if(!empty($notice_array))
        $sql .= " and wr_id not in (".implode(', ', $notice_array).") ";
    echo $sql .= " {$sql_order} limit {$from_record}, $page_rows ";
}

 

============================

/bbs/search.php

 

    $sql_search = $str;

    //#조건노출
    if ($bo_table=="테이블명" && !$is_admin) {
        $sql_search .= " and row_show = 1 ";
    }


    $str_board_list = "";
    $board_count = 0;

 

 

버그가있는 경우 댓글로 정정 부탁드립니다.

 

|

댓글 5개

학습 잘 해서 적용해보겠습니다 감사합니다
2021-07-07 (수) 11:19:02
좋은 팁 올려주셔서 감사합니다.
2021-07-10 (토) 22:59:14
좋은팁이네요 감사합니다.
I don’t think my columns are ever satisfied whatever I try. Maybe I input a wrong character in the code somewhere. Is there an AI that can help seek where the problem is?
2021-08-21 (토) 23:59:19
@Kirsten I think there is no AI like that. if you want edit code, you have to learn PHP.
댓글을 작성하시려면 로그인이 필요합니다.

그누보드5 팁자료실

2,788건
+
제목 글쓴이 날짜 조회
21-07-23 조회 7,255
21-07-23 조회 5,805
21-07-16 조회 7,284
21-07-14 조회 6,068
21-07-14 조회 4,725
21-07-12 조회 5,348
21-07-12 조회 5,206
21-07-09 조회 5,866
21-07-07 조회 5,165
21-07-06 조회 5,678
21-07-05 조회 6,510
21-07-05 조회 6,228
21-07-01 조회 6,207
21-06-30 조회 5,417
21-06-29 조회 8,440
21-06-29 조회 6,956
21-06-29 조회 7,879
21-06-29 조회 6,813
21-06-27 조회 6,971
21-06-24 조회 8,090
21-06-24 조회 7,041
21-06-24 조회 5,799
21-06-23 조회 9,634
21-06-22 조회 7,609
21-06-22 조회 4,802
21-06-20 조회 7,110
21-06-20 조회 5,026
21-06-19 조회 6,126
21-06-17 조회 5,967
21-06-16 조회 7,266