최신글 쿼리 한번 봐주세요 ㅠㅠ

최신글 쿼리 한번 봐주세요 ㅠㅠ

QA

최신글 쿼리 한번 봐주세요 ㅠㅠ

본문

latest.lib.php

 

에서  - sql 조건 :

본인글 + wr_2 array 안에 id 있으면 가져오기

 

#  최신글 중에 본인의 글 + wr_2 (array 값으로 mb_id 있음 - #######,#######,#######...........)안에  본인 아이디 있으면 그글도 가져오기 를 만들고 있읍니다.

아래와 같이  주석부분을 만들었는데 작동을 하지 않읍니다.

 

개념 자체가 틀린건지 고견 부탁드립니다. ~

 


    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 {$options} 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.mb_id = '{$member[mb_id]}' ";        
// ---------------------------그룹 최신글 쿼리중에 b.wr_2 안에 array(,) 로 들어가 있는 아이디와 비교하여 있으면 가져오기-----------------------------------------//
//          $array_wr2 = explode(',', trim('b.wr_2'));        //
//          $sql_common .= " or in_array('{$member[mb_id]}', $array_wr2) ";        //
// --------------------------------------------------------------------------------------------------------------------------------------------------------------//
          $sql_common .= " and a.bo_table not in ('notice') ";
        $sql_common .= " and a.wr_id = a.wr_parent ";
        $sql_order = " order by a.bn_datetime desc ";
        $sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id {$sql_common} {$sql_order} limit 0, {$rows}";
        $result = sql_query($sql);

이 질문에 댓글 쓰기 :

답변 4

$sql_common .= " or in_array('{$member[mb_id]}', $array_wr2) "; 

in_array는 PHP 함수이기때문에 쿼리에 사용이 될 수 없습니다.

OR mb_id IN ('aaa', 'bbb', 'ccc')

의 형식으로 바꾸셔야 합니다.

 

전체 쿼리의 내용을 출력하여 올려주시면 더 좋은 답변이 가능할거라고 생각됩니다.

아래처럼 수정하시고, 잘 되면 좋은거고 안되면 echo를 이용하여 쿼리를 출력해서 보여주세요.

 



    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 {$options} a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = 1 ";
        /* === 위 라인 주석 처리 후 아래와 같이 고치세요. where 뒤에 좌괄호 추가함. === */
        $sql_common = " from {$g5['board_new_table']} a, {$g5['board_table']} b, {$g5['group_table']} c where ( {$options} 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' ";
// --그룹 최신글 쿼리중에 b.wr_2 안에 array(,) 로 들어가 있는 아이디와 비교하여 있으면 가져오기--//
//        $sql_common .= " and a.mb_id = '{$member[mb_id]}' ";
//          $array_wr2 = explode(',', trim('b.wr_2'));        //
//          $sql_common .= " or in_array('{$member[mb_id]}', $array_wr2) ";        //
// --------------------------------------------------------------------------------------------------------------------------------------------------------------//
          $sql_common .= " and a.bo_table not in ('notice') ";        
        $sql_common .= " and a.wr_id = a.wr_parent "; 
/* === 아래 내용 추가하세요. = 위의 AND 조건에 OR를 추가하기 위하여 괄호가 들어갑니다. = */
     $sql_common = " ) OR b.wr_2 LIKE '%". $member[mb_id] ."%' "; 
/* ===================================================================================== */ 
        $sql_order = " order by a.bn_datetime desc ";
        $sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id {$sql_common} {$sql_order} limit 0, {$rows}";
/* === 상상으로 코딩하기에 정확한 판단이 어렵네요. 안된다면 echo를 찍어서 보여주세요. === */
           echo "sql ===> ". $sql ."<br>";
           echo "array_wr2 ===> ". $array_wr2 ."<br>";
/* === ================================================================================== */
        $result = sql_query($sql);
        for ($i=0; $row=sql_fetch_array($result); $i++) {

네 친절한 답변 감사합니다 개념 자체가 틀린거 였군요 ~~

아래는 제가 쓰고있는 그룹 최신글 입니다.

 

혹시 간단하게 할수 있으면 도와 주시면 감사하겠읍니다 ~

 


// 최신글 추출
// $cache_time 캐시 갱신시간
function latest_group($skin_dir='', $gr_id, $rows=10, $subject_len=40, $cache_time=1, $options='')
{
    global $g5, $is_admin, $member;
    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 {$options} 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' ";
// ---------------------------그룹 최신글 쿼리중에 b.wr_2 안에 array(,) 로 들어가 있는 아이디와 비교하여 있으면 가져오기-----------------------------------------//
//        $sql_common .= " and a.mb_id = '{$member[mb_id]}' ";
//          $array_wr2 = explode(',', trim('b.wr_2'));        //
//          $sql_common .= " or in_array('{$member[mb_id]}', $array_wr2) ";        //
// --------------------------------------------------------------------------------------------------------------------------------------------------------------//
          $sql_common .= " and a.bo_table not in ('notice') ";        
        $sql_common .= " and a.wr_id = a.wr_parent "; 
        $sql_order = " order by a.bn_datetime 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;
}
 

친절한 답변 감사합니다. ~~

 

일단 안되는 군요 ~.....

 

like 문 써야 하는거 까지는 공부가 된거 같읍니다.

 

제능력 밖이라 제작의로로 갑니다 ㅠㅠ

 

감사합니다.

 

답변을 작성하시기 전에 로그인 해주세요.
전체 9
QA 내용 검색

회원로그인

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