새 글수 출력 팁을 사용하려고 합니다 채택완료
안녕하세요?
익명닉네임니의 팁을 사용하려고 합니다.
* [10년전 재탕 팁]메뉴 NEW 아이콘 또는 새글수 출력 (분류도 지원) → https://sir.kr/g4_tiptech/34031">https://sir.kr/g4_tiptech/34031
그대로 사용해도 될 것 같아서 g4 를 g5로 바꿨는데 새로운 글 숫자가 안 나타나는군요~
어디를 손을 더 봐야하는지요~
추석연휴 몸 건강하시고 고향 길 편히 다녀오십시오~^^)
감사합니다.
<?php
//24시간 이내의 글 수 알아내기
function new_count($table_id,$ca_name,$cmt){
// 오늘을 불러옵니다.
$intime = date("Y-m-d H:i:s", time() - (int)(60 * 60 * 24));
// 여기는 오늘과 글쓴 날짜를 비교합니다.
$tmp_write_table .= "g5_write_$table_id";
if($cmt){
$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment = '$cmt' and ca_name = '$ca_name' ";
}else{
$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and ca_name = '$ca_name' ";
}
// 새로운 글이 몇개 있는지 확인합니다.
$result2 = sql_query($sql2);
$total_count = mysql_num_rows($result2);
if ($total_count > 0) {
$str_cnt .= " [".$total_count."]"; //새글수
$str_cnt .= ""; //이미지
return $str_cnt;
}
else {
$str_cnt .= "";
return $str_cnt;
}
}
?>
<?php
//자유게시판 새로운 글 출력방법
//new_count("게시판명","분류명","0 게시물만 | 1 댓글만 | 빈 공간 둘다 ");
new_count("free","","0");
?>
답변 5개
</p><p><?php </p><p><span style="font-size: 11pt;">//24시간 이내의 글 수 알아내기 </span> </p><p>function new_count($table_id,$ca_name,$cmt){ </p><p>// 오늘을 불러옵니다. </p><p>$intime = date("Y-m-d H:i:s", time() - (int)(60 * 60 * 24)); </p><p>
</p><p>// 여기는 오늘과 글쓴 날짜를 비교합니다. </p><p>$tmp_write_table .= "g5_write_$table_id"; </p><p>if($cmt){</p><p>$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment = '$cmt' and ca_name = '$ca_name' "; </p><p>}else{</p><p>$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and ca_name = '$ca_name' "; </p><p>}</p><p>// 새로운 글이 몇개 있는지 확인합니다. </p><p>$result2 = sql_query($sql2); </p><p>$total_count = sql_num_rows($result2); </p><p>
</p><p>if ($total_count > 0) { </p><p>$str_cnt .= " [".$total_count."]"; //새글수 </p><p>$str_cnt .= ""; //이미지 </p><p>return $str_cnt; </p><p>} </p><p>else { </p><p>$str_cnt .= ""; </p><p>return $str_cnt; </p><p>} </p><p>} </p><p>
</p><p>//자유게시판 새로운 글 출력방법 </p><p>//new_count("게시판명","분류명","0 게시물만 | 1 댓글만 | 빈 공간 둘다 ");</p><p>echo new_count("free","<span style="font-size: 16px;"><b><u>분류값 필수!</u></b></span>","0");</p><p>?></p><p>
분류명에 값을 안넣으시면 쿼리문에서 못 불러옵니다
답변에 대한 댓글 3개
//24시간 이내의 글 수 알아내기
function new_count($table_id,$ca_name,$cmt){
// 오늘을 불러옵니다.
$intime = date("Y-m-d H:i:s", time() - (int)(60 * 60 * 24));
// 여기는 오늘과 글쓴 날짜를 비교합니다.
$tmp_write_table .= "g5_write_$table_id";
$ca_sql="";
if ($ca_name) $ca_sql=" and ca_name = '$ca_name'";
if($cmt){
$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment = '$cmt' ";
}else{
$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' ";
}
$sql2.=$ca_sql;
// 새로운 글이 몇개 있는지 확인합니다.
$result2 = sql_query($sql2);
$total_count = sql_num_rows($result2);
if ($total_count > 0) {
$str_cnt .= " [".$total_count."]"; //새글수
$str_cnt .= ""; //이미지
return $str_cnt;
}
else {
$str_cnt .= "";
return $str_cnt;
}
}
//자유게시판 새로운 글 출력방법
//new_count("게시판명","분류명","0 게시물만 | 1 댓글만 | 빈 공간 둘다 ");
echo new_count("test","","0");
?>
플래토님 답변참고하여 수정했습니다
이렇게 한번 해보세요 분류명 있으시면 넣으시고 안넣으셔도 상관 없습니다~
테스트 해보니 잘 작동합니다 ㅠㅠ;
echo new_count("test","","0"); 또는 new_count("test","","0");
이상하게도 이 문구만 들어가면 어디에서 충돌이 나는지 css가 이상해지면서 페이지가
멈춰버리는군요~
아뭏든 참고하여 연구해 보겠습니다,
감사합니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 주신 모든 분께 감사드립니다.
다른 분도 참조하시라고 여기에 해결한 팁을 올려 드립니다.
* 메뉴부분에서 오늘 새글 표시하기 → https://sir.kr/g4_tiptech/1279">https://sir.kr/g4_tiptech/1279 에서 답을 얻었습니다.
rang2ya님의 답변을 조금 수정하여 적용하니 잘 되고 있습니다.
모든 분들 추석연휴 잘 보내시고 고향 길 잘 다녀오십시오~^^)
1. 다음과 같은 함수를 필요한 곳(상단 등) 넣으시고
<?php
//24시간 이내의 글 수 알아내기
function new_count($table_id){
// 오늘을 불러옵니다.
$intime = date("Y-m-d H:i:s", time() - (int)(60 * 60 * 24));
// 여기는 오늘과 글쓴 날짜를 비교합니다.
$tmp_write_table .= "g5_write_$table_id";
//$sql2 = "select wr_datetime from $tmp_write_table where wr_datetime >= '$intime'"; // 댓글 포함
$sql2 = "select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment=0"; // 댓글 제외
// 새로운 글이 몇개 있는지 확인합니다.
$result2 = sql_query($sql2);
$total_count = mysql_num_rows($result2);
if ($total_count > 0) {
$str_cnt .= " <font style='font-weight:normal;font-size:12px;color:blue';>(".$total_count.")</font>";
return $str_cnt;
}
else {
$str_cnt .= "";
return $str_cnt;
}
}
?>
2. 그리고 다음 구문을 원하시는 곳(수동메뉴 옆 또는 head.php 등 필요한 곳) 옆에 붙혀 주십시오~
예를 들어 자유게시판 이라면
<?=new_count(free);?>
댓글을 작성하려면 로그인이 필요합니다.
new_count("free","","0");
이렇게 호출하신게 오류입니다.
위의 소스코들르 보면 어디를 봐도 두번째 인자값에 대한
구문이 있어야만 하는 구조입니다.
ca_name = '$ca_name'
ca_name ='' 인것만 가져오기라는 형태로 적용될테니
제가 약간 변경을 해보면
</span></span></p><p><span style="font-family: Arial, 돋움, Dotum; color: rgb(72, 72, 72);"><span style="font-size: 14.004px;">// 기존코드</span></span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">if($cmt){</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment = '$cmt' and ca_name = '$ca_name' "; </p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}else{</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and ca_name = '$ca_name' "; </p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">
</span></p><p><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">// 변경된 코드</span></p><p><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$ca_sql = "";</span></p><p style="margin-left: 0px;"><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">if ($ca_name)</span></p><p style="margin-left: 0px;"><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> $ca_sql = " and ca_name = '$ca_name' ";</span></p><p><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">
</span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">if($cmt){</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> $sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' and wr_is_comment = '$cmt' "; </p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}else{</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> $sql2 = " select wr_datetime from $tmp_write_table where wr_datetime >= '$intime' "; </p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">
</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$sql2 .= $ca_sql;</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">
로 해보시면 나올텐데
그래도 안나오실경우 호출하실때
new_count("free","",0);
으로 변경해보시는것도 추천합니다.
답변에 대한 댓글 1개
그런데 잘 안 됩니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
그런데 잘 안 됩니다.
그리고 echo new_count("free","분류값 필수!","0");
이렇게 echo를 넣으니까 뭐가 잘 못 되었는지 css가 이상해지면서 페이지가
멈춰버리는군요~