그누보드 어드민에서 union 처리 문의

그누보드 어드민에서 union 처리 문의

QA

그누보드 어드민에서 union 처리 문의

본문

실제 db에서 union하여 쿼리하면 두개 테이블이 통합되어 잘 나오는데

그누보드 어드민에서 아래와 같이 처리하면 안나오네요

 

 

아래 소스 상에 $sql_common에  원소스는 item07 테이블로 지정 ==> 정상적으로 쿼리됨

$sql_common하나의 이상의 테이블을 union 하였을 경우  데이타가 나오지 않습니다. 

 

 

//$sql_common = " from (g5_write_item07 ) ";

$sql_common = " from (select wr_id, wr_datetime from g5_write_item07 union select wr_id, wr_datetime from g5_write_item08) x  ";

 

 

실제 db에서 아래와 같이 쿼리를 하면 정상적으로 잘 나옵니다.

select count(*) as count from (select wr_id, wr_datetime from g5_write_item07 union select wr_id, wr_datetime from g5_write_item08) x  where wr_is_comment = 0 order by $sst $sod, wr_id ;


 

코드는 총합 체크하는 부분만 남겼습니다.

 

일단 총 등록건수가 union 테이블을로 변경하면 0으로 나옵니다 

 5d0513739c485151a9778f8296f615a3_1478756184_4056.png
 


 
<?php
$sub_menu = "500700";
include_once('./_common.php');
 
auth_check($auth[$sub_menu], 'r');
 
//$sql_common = " from (g5_write_item07 ) ";
$sql_common = " from (select wr_id, wr_datetime from g5_write_item07 union select wr_id, wr_datetime from g5_write_item08) x ";
                  
if (!$sst) {
    $sst  = "wr_datetime";
    $sod  = "desc";   
}
 
if ($stx && !$showmode) {
    $sql_search = " where $sfl like '%$stx%' and wr_is_comment = 0 ";
} else {
    $sql_search = " where wr_is_comment = 0 ";
    $sql_order = " order by $sst $sod, wr_id ";
}
 
//총 등록 건 수 
$sql = " select count(*) as cnt {$sql_common} {$sql_search} {$sql_order} ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
 
//페이지당 노출 건수
$rows = $config['cf_page_rows'];
 
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page < 1) { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함
 
//데이터 처리 쿼리
$sql = " select * {$sql_common} {$sql_search} {$sql_order} limit {$from_record}, {$rows} ";
$result = sql_query($sql);
 
$listall = '<a href="'.$_SERVER['SCRIPT_NAME'].'" class="ov_listall">전체목록</a>';
 
$g5['title'] = $showtitle;
if(!$g5['title']) {$g5['title'] = "정보지";}
include_once('./admin.head.php');
 
$colspan = 15;
?>
 
<div class="local_ov01 local_ov">
    <?php echo $listall ?>
    총 등록건수 <?php echo number_format($total_count) ?>개
</div>
 
 
<!---->
 
<script>
function fboardlist_submit(f)
{
    if (!is_checked("chk[]")) {
        alert(document.pressed+" 하실 항목을 하나 이상 선택하세요.");
        return false;
    }
 
    if(document.pressed == "선택삭제") {
        if(!confirm("선택한 자료를 정말 삭제하시겠습니까?")) {
            return false;
        }
    }
 
    return true;
}
 
$(function(){
    $(".board_copy").click(function(){
        window.open(this.href, "win_board_copy", "left=100,top=100,width=550,height=450");
        return false;
    });
});
</script>
 
<?php
include_once('./admin.tail.php');
?>

 

 

이 질문에 댓글 쓰기 :

답변 2

phpmyadmin에서는 실행을 해 보셨죠?

sql_query, sql_fetch 이 두 함수에서 union을 풀었을지 모르겠네요.

기본 코드는 union 제한하고 있어서 그누에서 제공하는 함수로는 값 갖고 올 수가 없습니다.

mysql_query, mysql_fetch_array 함수 사용하셔야 합니다. 

db에서
select count(*) as count from (select wr_id, wr_datetime from g5_write_item07 union select wr_id, wr_datetime from g5_write_item08) x  where wr_is_comment = 0 order by $sst $sod, wr_id ;
이렇게 쿼리 요청 시 정상적으로 나오는거 확인은 했는데요


$sql = " select count(*) as cnt $sql_common  ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];


모두 바꿔야 하는건가요?

union은 해킹에 위험도가 높은 쿼리명령어여서.. 왠만한 프로그램에서는 사용을 제한 해요.  

 

 

안쓰시는 것을 추천해드리고 싶어요. 

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

회원로그인

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