하루에 글 1회만 작성가능하게 한것을 수정하고 싶습니다.

하루에 글 1회만 작성가능하게 한것을 수정하고 싶습니다.

QA

하루에 글 1회만 작성가능하게 한것을 수정하고 싶습니다.

본문

$sql = " select count(*) as cnt from $write_table where mb_id = '$member[mb_id]' and wr_datetime like '".G5_TIME_YMD."%' ";
$row = sql_fetch($sql);
if ($row[cnt] > 0 & !$is_admin) {
    alert("이미 오늘 글쓰기 가능횟수 1회를\\n모두 소진 하셨습니다.");
}​

 

이렇게 되면 글쓰기 가능횟수가 자정에 초기화가 되는데

이것을 오전 9시로 변경하고 싶습니다... 어떻게 해야 할지 도통 감이 안잡히네요.

이 질문에 댓글 쓰기 :

답변 1

쿼리구문을 바꿔보세요.

$sql = " select * from count(*) as cnt where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD." 09:00:00') < unix_timestamp(wr_datetime) "; 

​select * from count(*) as cnt​ where mb_id = 'admin​' and unix_timestamp('2015-04-21​ 09:00:00') < unix_timestamp(wr_datetime)

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 '​select * from count(*) as cnt​ where mb_id = 'admin​' and unix_timestamp(' at line 1

error file : /bbs/bbs/write.php

$sql = "select count(*) as cnt​  from $write_table where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD."​ 09:00:00') < unix_timestamp(wr_datetime)";
이렇게 적용했더니 구문오류는 뜨지않으나 적용이 되지 않습니다..

그럼 그 게시판에 해당조건에 부합하는 레코드가 없는거죠.
결과물 mysql 상에서 바로 확인해서 보시려면..
echo $sql; 찍어서 phpmyadmin 이나 mysql console 에서 확인해보세요.

적어드린 쿼리문자체는 해당게시판에 접속한 현재날짜의 9시 이후 내가 작성한 게시물이 몇개인지를 세어보는 쿼리니까요.

select count(*) as cnt​ from g5_write_freeboard where mb_id = 'admin' and unix_timestamp('2015-04-22​ 09:00:00') < unix_timestamp(wr_datetime)
이렇게 나오네요.
wr_datetime이 최근 글 작성 시간으로 나와야 하는데
저렇게 나와요 ㅠㅠ

$sql = "select count(*) as cnt​  from $write_table where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD."​ 09:00:00') < unix_timestamp('$_wr_datetime')";

이렇게 수정하여 작성하오니
select count(*) as cnt​ from g5_write_freeboard where mb_id = 'admin' and unix_timestamp('2015-04-22​ 09:00:00') < unix_timestamp('2015-04-22 02:39:43')
이렇게 정상적으로 나오나 역시나 작동은 하지 않습ㄴ디ㅏ ㅠㅠ

echo 결과로 받은 아래 쿼리를 phpmyadmin 등에서 실행해 보세요. 그럼 결과값이 비었는지 갯수가 나오는지 아실거 아닌가요?
select count(*) as cnt​ from g5_write_freeboard where mb_id = 'admin' and unix_timestamp('2015-04-22​ 09:00:00') < unix_timestamp('2015-04-22 02:39:43')

전체소스를 보지않는이상 쿼리외에 어떤이상이 잇는지 까지는 제가 답변해 드릴수가 없어요.

phpmyadmin에서 실행할 경우에
SELECT count( * ) AS cnt​
FROM g5_write_freeboard
WHERE mb_id = 'admin'
AND unix_timestamp( '2015-04-22​ 09:00:00' ) < unix_timestamp( '2015-04-22 03:12:30' )

cnt​
26
이렇게 나옵니다.
그리고 전체소스도 이것뿐 입니다.

<?
$sql = "select count(*) as cnt​  from $write_table where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD."​ 09:00:00') < unix_timestamp('$_wr_datetime')";
$row = sql_fetch($sql);
if ($row[cnt] > 0) {
    alert("이미 오늘 인증횟수 1회를\\n모두 소진 하셨습니다.");
}
?>

저 cnt 26개는 오늘만 쓴글이 아니라
freeboard 전체에 쓴 게시물수입니다..

admin 으로 로그인은 한상태에서 테스트하셨나요?
로그인이 안되어 있다면 쿼리가 달라집니다. mb_id='' 으로 반영되는거죠

그리고 작성된 쿼리에서

<?
$sql = "select count(*) as cnt​  from $write_table where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD."​ 09:00:00') < unix_timestamp('$_wr_datetime')";
$row = sql_fetch($sql);
if ($row[cnt] > 0) {
    alert("이미 오늘 인증횟수 1회를\\n모두 소진 하셨습니다.");
}
?>

'$_wr_datetime' <- 이거 아닙니다. wr_datetime 필드명만 적어야 됩니다. 이렇게 했으면 결과가 당연히 맞게 안나옵니다.
그리고 자꾸 문의주시길래.. 확인해봤습니다. 이상없는 코드입니다.

<?
$sql = "select count(*) as cnt​  from $write_table where mb_id = '$member[mb_id]' and unix_timestamp('".G5_TIME_YMD."​ 09:00:00') < unix_timestamp(wr_datetime)";
echo $sql;
$row = sql_fetch($sql);
if ($row[cnt] > 0) {
    alert("이미 오늘 인증횟수 1회를\\n모두 소진 하셨습니다.");
}
?>

이렇게 소스를 사용하였고
select count(*) as cnt​ from g5_write_Sean where mb_id = 'admin' and unix_timestamp('2015-04-22​ 09:00:00') < unix_timestamp(wr_datetime)
이것도 myphpadmin에 돌려보니
cnt 가 4개로 나왔습니다.
그러나 정상적으로 작동하진 않습니다...

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

회원로그인

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