그누보드 어드민에서 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으로 나옵니다
<?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 함수 사용하셔야 합니다.
union은 해킹에 위험도가 높은 쿼리명령어여서.. 왠만한 프로그램에서는 사용을 제한 해요.
안쓰시는 것을 추천해드리고 싶어요.