게시물 당 댓글 허용 수 1인 1개로 제한할 수 있을까요??

게시물 당 댓글 허용 수 1인 1개로 제한할 수 있을까요??

QA

게시물 당 댓글 허용 수 1인 1개로 제한할 수 있을까요??

본문


<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
if($result['cnt']<"1") {
?>
<div class="res_btn">신청서 작성</button>
            <?php } ?>

 

이미 댓글을 달았을 때 버튼이 안보이는게 아니라

이미 댓글을 달았다면 버튼 클릭시 alert 창이 보이게 하고싶은데 어떻게 해야할까요?

이 질문에 댓글 쓰기 :

답변 1


<?php
 
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="alert(\'신청서를 이미작성하셨습니다.\'); event.stopPropagation();"' : '';
?>
 
<div class="res_btn" <?php echo $addEvent; ?>>신청서 작성</button>

<?php
 
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="alert(\'신청서를 이미작성하셨습니다.\'); return false;"' : '';
?>
 
<div class="res_btn" <?php echo $addEvent; ?>>신청서 작성</button>

필립스님 감사합니다. 해결하였습니다! php에 대해 잘 몰라서 제가 알고있는 jquery와 필립스님이 말씀해주신 것으로 응용해서 해보니 잘 되네요!


<?php
$result = sql_fetch(" select count(*) as cnt from $write_table where wr_is_comment='1' and wr_parent='$view[wr_id]' and mb_id='$member[mb_id]'");
$addEvent = ($result['cnt'] > 0) ? 'onclick="res_notice()"' : '' ;
?>
<div class="res_btn" <?php echo $addEvent; ?> style="cursor:pointer;">신청서 작성</button>
<?php } ?>

이런식으로 jquery 스크립트를 받아와 기존 버튼의 클릭 이벤트를 날려주고 다시 새로고침하여, 버튼의 기능을 다시 살려주었습니다.

function res_notice() {
    alert("이미 신청서를 작성하셨습니다. 신청이 반려되었을 경우 삭제 후 다시 신청해주세요.");
    $(".res_btn").attr('onclick', '').unbind('click');
    window.location.reload();
}

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

회원로그인

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