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

안녕하세요.

 

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

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

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

도움을 부탁드립니다.

 

Copy
$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개 / 댓글 2개

 댓글쓴사람의 목록을 중복없이

===

처음 질문이 이거였다면 다들 산에 있지는 않을 겁니다.

select distinct mb_id from...

이렇게 하시면 됩니다.

 

Copy
$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가 제외된 모든 댓글을 추출하려면

Copy
<?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 ";

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

 

위의 질문에 올리신 쿼리는

 

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

 

 

답변에 대한 댓글 1개

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

말씀주신대로 적용하니 정말 특정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라인을 가보면

처음에 정의내렸던

[code]
<?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']));
}
}
?>
[/code]

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

[code]
<?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
}
?>
[/code]

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

 $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이 어떻게 나오는 보세요.

 

답변에 대한 댓글 1개

echo 에서 출력해보니 wr_id_str 값이 글의 wr_id 값(숫자)이 나오네요!

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

 

 $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

답변을 작성하려면 로그인이 필요합니다.

🐛 버그신고