글 작성시 카테고리에 글이 있으면 작성 못하게 하는 법..ㅠㅠ 채택완료
midm
6년 전
조회 2,490
어떻게 검색해서 카테고리와 글 작성 관련 코드를 긁어 짜집기했습니다...ㅠㅠ
해당 스킨의 write.skin.php 하단에
</p>
<p>$tmp_write_table .= "게시판 이름";</p>
<p>$sql2 = sql_fetch("SELECT COUNT(*) AS cnt FROM g5_write_게시판이름 WHERE ca_name = '카테고리이름' and wr_is_comment = '0'");</p>
<p>$total_count = $sql2['cnt'];</p>
<p> </p>
<p>if ($is_category) {</p>
<p>if ($total_count > 1)
alert "해당 카테고리엔 더이상 작성 불가합니다"; </p>
<p>return false;</p>
<p> }</p>
<p> return true;
}
</script>
</section>
<!-- } 게시물 작성/수정 끝 --></p>
<p>
이렇게 넣었는데 아무리 작성해도 글이 너무 잘 써집니다ㅠㅠㅠ...
어디를 어떻게 고쳐야 이게 기능할까요!
해당 카테고리에 글이 1개 이상 있다면 작성 눌렀을 때 알람이 뜨면서 해당 카테고리에 글 작성 못하게 하고 싶습니당 ㅠㅠㅠ
제가 아직 너무 초보라..
도와주시면 감사하겠습니다..ㅠㅠ
댓글을 작성하려면 로그인이 필요합니다.
답변 1개
채택된 답변
+20 포인트
6년 전
echo "SELECT COUNT(*) AS cnt FROM g5_write_게시판이름 WHERE ca_name = '카테고리이름' and wr_is_comment = '0'";
exit;
위의 쿼리문은 잘못된 부분이 없는것 같네요..
위에 쿼리문을 DB에 직접 실행해보세요..
게시판이름 또는 카테고리이름 에서 오류가 있을것 같네요..
로그인 후 평가할 수 있습니다
답변에 대한 댓글 3개
m
midm
6년 전
e
eyekiss
6년 전
for문 안쪽으로 넣어주세요..
<?php
$categories = explode('|', $board['bo_category_list']); // 구분자가 , 로 되어 있음
for ($i=0; $i<count($categories); $i++) {
$category = trim($categories[$i]);
$sql2 = sql_fetch("SELECT COUNT(*) AS cnt FROM $write_table WHERE ca_name = '$category' and wr_is_comment = '0'");
$total_count = $sql2['cnt'];
$category_radio .= '<label for="'.$category.'"><INPUT type="radio" disabled="" name="ca_name" id="'.$category.'" ';
$category_radio .= 'value="'.$category.'"';
if($category == $ca_name) $category_radio .= " checked";
if($total_count == 1) $category_radio .= 'disabled';
$category_radio .= "> ".$category." <img src='../".$category.".jpg'> </label>";
}
echo $category_radio;
?>
<?php
$categories = explode('|', $board['bo_category_list']); // 구분자가 , 로 되어 있음
for ($i=0; $i<count($categories); $i++) {
$category = trim($categories[$i]);
$sql2 = sql_fetch("SELECT COUNT(*) AS cnt FROM $write_table WHERE ca_name = '$category' and wr_is_comment = '0'");
$total_count = $sql2['cnt'];
$category_radio .= '<label for="'.$category.'"><INPUT type="radio" disabled="" name="ca_name" id="'.$category.'" ';
$category_radio .= 'value="'.$category.'"';
if($category == $ca_name) $category_radio .= " checked";
if($total_count == 1) $category_radio .= 'disabled';
$category_radio .= "> ".$category." <img src='../".$category.".jpg'> </label>";
}
echo $category_radio;
?>
m
midm
6년 전
헐... 성공했어용 ㅠㅠㅠㅠ 됐습니다ㅠㅠㅠㅠㅠ 감사합니다ㅠㅠㅠㅠ for 안에 if에 쓸 변수를 선언해야 하는 거군요..!! 감사합니다!!!!!!!!!!!!!
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
<?php
$sql2 = sql_fetch("SELECT COUNT(*) AS cnt FROM $write_table WHERE ca_name = '$ca_name' and wr_is_comment = '0'");
$total_count = $sql2['cnt'];
$categories = explode('|', $board['bo_category_list']); // 구분자가 , 로 되어 있음
for ($i=0; $i<count($categories); $i++) {
$category = trim($categories[$i]);
$category_radio .= '<label for="'.$category.'"><INPUT type="radio" name="ca_name" id="'.$category.'" ';
$category_radio .= 'value="'.$category.'"';
if($category == $ca_name) $category_radio .= " checked";
if($total_count == 1) $category_radio .= 'disabled';
$category_radio .= "> ".$category." <img src='../".$category.".jpg'> </label>";
}
echo $category_radio;
?>[/code]
그렇다면 이건 문법에 맞는 건가요?ㅠㅠ
if($total_count == 1) $category_radio .= 'disabled'; 이걸 써서 카테고리에 작성한 글이 1개 이상 넘는 건 라디오버튼으로 만든 카테고리 disable로 하려고 했습니당
for문 안에 echo로 $total_count 불러오면 잘 출력되는데, for문 안에 if문으로 조건 넣으려니까 작동이 아예 안 돼요ㅠㅠㅠㅠ display:none으로 숨겨놓고 label로 체크할 수 있게 만들었습니다.. 그런데 저 if문만 들어가면 조건 상관 없이 전부 disable이에요.. 뭐가 문제일까요?