테스트 사이트 - 개발 중인 베타 버전입니다

99%되었는데 사용환경땜에 앙되네요.. 채택완료

민쯩먼저깔게요 8년 전 조회 1,811

슈와이님이 알려주셔서 잘 되는데요,,

제가 쓰려는 상황이 적용해보니 약간 변수가 있네요

$sql = " select * from  {$write_table}  where wr_is_comment = 0 and wr_id not in ({$board['bo_notice']}) and wr_21 != '' order by wr_num limit 1 ";

$result = sql_fetch($sql);

echo $result['wr_21']+1;

?>

이건데요,,,

공지를 제외하고 가장 최신글의 wr_21의 값에 +1을 더해서 리스트 상단에 숫자를 표시하려는데요...

새글을 다른곳에서 복사해오면 그게 이게시판의 최신글이 되는데.. 

복사해오는 글에는 wr_21값이 없습니다. 그래서 직전 최신글에 +1해서 잘나오는데요..

문제는 복사해오지 않고 현재 상태에서 가장최신글의 wr_21에 값이 있으므로 그거에 +1을 해서 숫자가 1큰수가 되어 안맞네요.,.

이런 상황에서

$sql = " select * from  {$write_table}  where wr_is_comment = 0 and wr_id not in ({$board['bo_notice']}) and wr_21 != '' order by wr_num limit 1 ";

$result = sql_fetch($sql);

 

if($result['wr_21'] =='') {

echo $result['wr_21']+1;

} else {

echo $result['wr_21'];

}

?>

이렇게도 해보았는데 숫자가 맞지 않네요,,

어떻게 해야 할지요,,흑흑

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

답변 2개

채택된 답변
+20 포인트
l
8년 전

wr_21 값이 없을 때는 이게시물이 아니고 바로 아래 게시물을 찾아 wr_21+1을 해라  

이렇게 하셔야 하는것으로 보이는데요

제가 테이블 구조를 잘 몰라서리.. ㅜㅜ 여튼 아래 쿼리와 비슷할 것 같긴 합니다

</span></p><p><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$sql = " select </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">wr_21 </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">from  {$write_table}  where wr_is_comment = 0 and wr_id not in ({$board['bo_notice']}) and wr_21 != '' AND </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">wr_num</span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> < {$wr_num} </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">order by wr_num DESC limit 1 ";</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;">// 참고로 </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$wr_num 은 $_POST['</span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">wr_num</span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">']  이거나 </span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">$_GET['</span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">wr_num</span><span style="color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> </span><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;">// 테이블 스키마도 잘 몰라서 답변이 좀 애매하네요</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(51, 51, 51); font-family: Arial, 돋움, Dotum; font-size: 12px; background-color: rgb(247, 247, 247);">
 

로그인 후 평가할 수 있습니다

답변에 대한 댓글 1개

민쯩먼저깔게요
8년 전
감사합니다~ 참고해서 성공해보겠습니다.
시간 내주셔서 감사드려요~

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

l
8년 전

</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"> <span style="font-size: 14.004px;">if($result['wr_21'] =='') {</span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"><span style="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;"><span style="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;"><span style="font-size: 14.004px;">    // 그냥 echo 1;  이런게 맞지 않을까요?</span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"><span style="font-size: 14.004px;">    // echo $result['wr_21']+1; </span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;"><span style="font-size: 14.004px;">    </span><span style="font-size: 14.004px;">echo 1;</span><span style="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;">} else {</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;">    // echo intval(<span style="font-size: 14.004px;">$result['wr_21']</span><span style="font-size: 14.004px;">) + 1;   이렇게 해야되지 싶네요</span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">    // echo $result['wr_21'];</p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">    <span style="font-size: 14.004px;">echo intval(</span><span style="font-size: 14.004px;">$result['wr_21']</span><span style="font-size: 14.004px;">) + 1; </span></p><p style="word-break: break-all; color: rgb(72, 72, 72); font-family: Arial, 돋움, Dotum; font-size: 14.004px;">}</p><p>

로그인 후 평가할 수 있습니다

답변에 대한 댓글 2개

민쯩먼저깔게요
8년 전
해볼게요~~
민쯩먼저깔게요
8년 전
여러가지로 해보았는데

if($result['wr_21'] =='') {
값이 없을 때는 이게시물이 아니고 바로 아래 게시물 wr_21+1을 해라
이게 맞는거 같아요 근데 짤능력이 안되서요,,

} else {
// 값이 있을 때는 이게 맞네요

echo $result['wr_21'];

}

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

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

로그인