특정 컬럼의 데이터를 제외하고 검색하기

특정 컬럼의 데이터를 제외하고 검색하기

QA

특정 컬럼의 데이터를 제외하고 검색하기

본문

안녕하세요.

 

게시판 list.php 에서 댓글쓴 사람의 id 목록을 가져오고 있는데요.

특정 사람(mb_id) 의 ID는 제외하고 값을 가져오고 싶어

 아래처럼 not in 구문을 사용했는데 작동하지를 않네요..ㅜㅜ

도움을 부탁드립니다.

 

 $sql = " select wr_id, wr_parent, wr_name, mb_id from $write_table where wr_parent IN ({$wr_id_str}) and mb_id not in ('testid') and wr_is_comment = 1 order by wr_comment, wr_comment_reply "; 

이 질문에 댓글 쓰기 :

답변 4

파란색코드 탓 아닐련지..

 

 $sql = " select wr_id, wr_parent, wr_name, mb_id from $write_table where wr_parent IN ({$wr_id_str}) and mb_id not in ('testid') and wr_is_comment = 1 order by wr_comment, wr_comment_reply "; 

 

PS. 해당 코드 제외하고 아래 코드로 테스트해보니 잘 됩니다.

select wr_id, wr_parent, wr_name, mb_id from g5_write_free where mb_id not in ('admin') and wr_is_comment = 1 order by wr_comment, wr_comment_reply

 $sql = " select wr_id, wr_parent, wr_name, mb_id from $write_table where wr_parent IN ({$wr_id_str}) and mb_id not in ('testid') and wr_is_comment = 1 order by wr_comment, wr_comment_reply "; 

echo $sql;

해서 한번 sql을 확인해 보세요.

$wr_id_str이 어떻게 나오는 보세요.

 


$sql = " select wr_id, wr_parent, wr_name, mb_id from $write_table 
           where wr_parent IN ({$wr_id_str}) and mb_id not in ('testid') and wr_is_comment = 1 
           order by wr_comment, wr_comment_reply "; 


이 쿼릴 보면

 

wr_parent 라는 wr_id 값을 한정하는 구문이 있네요

wr_id 와 wr_parent 는 본문

wr_id <> wr_parent 이고 wr_comment = 1 은 댓글이 됩니다.

 

따라서 특정게시판의 댓글중에 특정 ID가 제외된 모든 댓글을 추출하려면


<?php

$sql = " SELECT wr_id, wr_parent, wr_name, mb_id FROM $write_table 
            WHERE mb_id not in ('testid') and wr_is_comment = 1 
             order by wr_comment, wr_comment_reply "; 

와 같은 방식으로 접근하시는게 맞습니다.

 

위의 질문에 올리신 쿼리는

 

특정게시물의 댓글중 이라는 형태로 한정하게 됩니다

 

 

[내용수정]
안녕하세요 플래토님!
늦은시간까지 정말 감사드립니다.^^

말씀주신대로 적용하니 정말 특정ID값만 빼고 가져오게되네요! 감사드립니다 ㅜㅜ

다만, 게시판 list.php 목록에 랜덤으로 아래와 같은 오류 메시지가 나타나는데요!

"Warning: Invalid argument supplied for foreach() in /www/theme/cld/moe/skin/bd/sr_01/list.skin.php on line 174"

해당 174라인을 가보면

처음에 정의내렸던


<?php
$wr_id_str = "";
foreach($list AS $k => $v) {
  if ($wr_id_str != "") {
    $wr_id_str .= ",";
  }

  $wr_id_str .= $v['wr_id'];
}

$reply_info = array();

if ($wr_id_str != "") {
  $sql = " select wr_id, wr_parent, wr_name, mb_id from $write_table where mb_id not in ('admin') and wr_is_comment = 1 order by wr_comment, wr_comment_reply "; 
  $result = sql_query($sql); 

  while($comment_row = sql_fetch_array($result)) {
    $reply_info[$comment_row['wr_parent']][$comment_row['mb_id']] = $comment_row;
    $reply_info[$comment_row['wr_parent']][$comment_row['mb_id']]['profile'] = str_replace(">", ' class="avatar">', get_member_profile_img($comment_row['mb_id']));
  }
}
?>


$wr_id_str을 불러와 아래와 같이 이용하고 있었습니다.


    <?php
          foreach ($reply_info[$list[$i]['wr_id']] as $key => $value)
						{
                        ?>
                        <li>
                          <a href="#" data-toggle="tooltip" title="<?=$value['wr_name']; ?>">
                            <?=$value['profile']?>
                          </a>
                        </li>
                        <?php
                        }
                        ?>


제가 하려는 것은 list.php 게시글 제목 옆에 댓글쓴사람의 목록을 중복없이 (댓글을 두번쓰더라도)
가져오려고 하는건데요,. 관리자의 댓글은 표시하지 않으려고 하는겁니다. ㅜㅜ
혹시 해당 오류를 없애려면 어떻게 해야할지 감이 오실까요 ㅜㅜ

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

회원로그인

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