말러님, 이미지 출력 권한별 제한 어떻게 하는건가요? > 그누4 질문답변

그누4 질문답변

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

말러님, 이미지 출력 권한별 제한 어떻게 하는건가요? 정보

말러님, 이미지 출력 권한별 제한 어떻게 하는건가요?

본문

http://sir.co.kr/bbs/tb.php/g4_qa/128679
====================================================

////////////////basic cf control///////////
$g4[g4_board_file] = "g4_board_file";  
$one_rows = "25";  // 이미지 출력수량
$width_o = "120"; //이미지 가로값
$height_o = "100"; //이미지 세로값
$cols  = "5"; //  이미지 가로갯수
$image_h  = "17"; // 이미지 상하 간격

$one_like   = " bo_table != 'mv' "; // 원하는 테이블 빼기
$two_like   = " AND bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' "; //jpg, jpeg, gif, png 파일만 검색한다.
$three_like = " AND bo_table IN (select bo_table from `$g4[board_table]` where bo_read_level <= '$member[mb_level]') as a "; // 게시판 읽기 권한초과한 게시판 이미지 제외

//$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where $one_like "; //원본
$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where $one_like $two_like $three_like ";
$row = sql_fetch($one_count_sql);
$total_count = $row[cnt];
$total_page  = ceil($total_count / $one_rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $one_rows; // 시작 열을 구함
$to_record = $from_record + $one_rows ;
     
//$one_sql      = " select * from $g4[g4_board_file] where $one_like order by bf_datetime desc limit $from_record, $one_rows"; // 원본
$one_sql      = " select * from $g4[g4_board_file] where $one_like $two_like $three_like order by bf_datetime desc limit $from_record, $one_rows"; // 추가
$one_result       = sql_query($one_sql);
?>

<!-----------기간별 출력시작--------->

위처럼 수정했는데요


행님께서 질문한 내용 1. 원하는 테이블 빼기와 2. 전체이미지 조회를 한 회원이 읽기 권한을 초과하는 게시판의 이미지는 불러오지 않기를 동시에 적용했는데, ( 2번만 적용했을때도 에러가 나네요.) 에러가납니다.

select count(*) as cnt from g4_board_file where bo_table != 'mv' AND bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' AND bo_table IN (select bo_table from `g4_board` where bo_read_level <= '10') as a

1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as a' at line 1

error file : /image_all/image_all.php


이런 에러가 떠요...

행님께서 말씀하신 특정 테이블 빼기와 함께 권한 안되는 게시물의 이미지는 출력이 안되게하게할려면 어떻게 수정해야하나요? 초보라서....ㅠㅠ

============================
서 버 버 전 : 5.0.42-log
서         버 : Localhost via UNIX socket
문   자   셋 : utf8
PHP 버 전 : 5.2.6-pl7-gentoo
===============================

  • 복사

댓글 전체

조건문에서 and가 우선적으로 처리됩니다.(덧셈 곱셈 섞이면 곱셈 먼저 하듯이) 괄호를 묶어줘야 해요.
혹시 다음과 같이 바꾸면 될까요?

($one_like) AND ($two_like) AND ($three_like)
$one_like  = " bo_table != 'mv' "; // 원하는 테이블 빼기
$two_like  = " AND bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' "; //jpg, jpeg, gif, png 파일만 검색한다.
$three_like = " AND bo_table IN (select bo_table from `$g4[board_table]` where bo_read_level <= '$member[mb_level]') as a "; // 게시판 읽기 권한초과한 게시판 이미지 제외

//$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where $one_like "; //원본
$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) ";
$row = sql_fetch($one_count_sql);
$total_count = $row[cnt];
$total_page  = ceil($total_count / $one_rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $one_rows; // 시작 열을 구함
$to_record = $from_record + $one_rows ;
     
//$one_sql      = " select * from $g4[g4_board_file] where $one_like order by bf_datetime desc limit $from_record, $one_rows"; // 원본
$one_sql      = " select * from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) order by bf_datetime desc limit $from_record, $one_rows"; // 추가
$one_result      = sql_query($one_sql);
?>


이렇게 했는데요.. 에러가 떠요...

맨위로select count(*) as cnt from g4_board_file where ( bo_table != 'mv' ) AND ( AND bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' ) AND ( AND bo_table IN (select bo_table from `g4_board` where bo_read_level <= '10') as a )

1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_fil' at line 1

error file : /image_all/image_all.php
AND가 연속으로 들어갔네요 괄호 안에 맨 앞의 AND를 지워주세요

쿼리문에 대해 공부하시려면 정보문화사에서 나온 "하루 10분씩 핵심만 골라 마스터하는 SQL 핸드북"을 추천합니다. 가격도 싸고 며칠만 공부하면 감 잡을 수 있더라고요. 책 한 권 읽어보심이..^^
$one_like  = " bo_table != 'mv' "; // 원하는 테이블 빼기
$two_like  = " bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' "; //jpg, jpeg, gif, png 파일만 검색한다.
$three_like = " bo_table IN (select bo_table from `$g4[board_table]` where bo_read_level <= '$member[mb_level]') as a "; // 게시판 읽기 권한초과한 게시판 이미지 제외

//$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where $one_like "; //원본
$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) ";
$row = sql_fetch($one_count_sql);
$total_count = $row[cnt];
$total_page  = ceil($total_count / $one_rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $one_rows; // 시작 열을 구함
$to_record = $from_record + $one_rows ;
     
//$one_sql      = " select * from $g4[g4_board_file] where $one_like order by bf_datetime desc limit $from_record, $one_rows"; // 원본
$one_sql      = " select * from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) order by bf_datetime desc limit $from_record, $one_rows"; // 추가
$one_result      = sql_query($one_sql);

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

select count(*) as cnt from g4_board_file where ( bo_table != 'mv' ) AND ( bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' ) AND ( bo_table IN (select bo_table from `g4_board` where bo_read_level <= '10') as a )

1064 : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'as a )' at line 1

error file : /image_all/image_all.php

흠 뭔가 잘못이해한걸까요ㅠㅠ?
sql 조건문 의 문제인 듯 합니다.

 접근(읽기) 레벨(3)이 가능한지를 파악한 후 먼저 제외시킬 테이블(1)을 제외하고 그 파일 중이서 4가지의 이미지(2)를 가져오는게 맞지 않나요 ?
as a 를 빼서 해결했습니다^^

근데 행님께서 하신 $one_like  = " bo_table != 'mv' "; // 원하는 테이블 빼기 이부분 여러테이블을 뺄려면

$one_like  = " bo_table != 'mv', '01', '02' "; // 원하는 테이블 빼기


이런식으로 해주면될까요?
아래와같이 해서 해결하였습니다.


$one_like  = " bo_table != 'mv' "; // 원하는 테이블 빼기
$two_like  = " bf_file LIKE '%jpg' or bf_file LIKE '%jpeg' or bf_file LIKE '%gif' or bf_file LIKE '%png' "; //jpg, jpeg, gif, png 파일만 검색한다.
$three_like = " bo_table IN (select bo_table from `$g4[board_table]` where bo_read_level <= '$member[mb_level]') "; // 게시판 읽기 권한초과한 게시판 이미지 제외

//$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where $one_like "; //원본
$one_count_sql = " select count(*) as cnt from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) ";
$row = sql_fetch($one_count_sql);
$total_count = $row[cnt];
$total_page  = ceil($total_count / $one_rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $one_rows; // 시작 열을 구함
$to_record = $from_record + $one_rows ;
     
//$one_sql      = " select * from $g4[g4_board_file] where $one_like order by bf_datetime desc limit $from_record, $one_rows"; // 원본
$one_sql      = " select * from $g4[g4_board_file] where ($one_like) AND ($two_like) AND ($three_like) order by bf_datetime desc limit $from_record, $one_rows"; // 추가
$one_result      = sql_query($one_sql);
?>

<!-----------기간별 출력시작--------->
© SIRSOFT
현재 페이지 제일 처음으로