··조회 14,473
또 찾아왔네요...ㅋㅋ
아래소스튼 코멘트소스인데요.. 원래소스는 while문까지만있고 그 밑의 if문은 ㅈㅔ가 추가한것인데요.. 제가 코멘트가 없는 경우 "없습니다"
라고 나오게 하려하는데... if 문으로 할라했는데... 좀 이상하게 나오네요... 글도 작성이 제대로 안되고.. 작성하면 없다는 코멘트분이 증가하네요.... 부탁드립니다. 염치없이 주말인데 또 들렸네요 ㅋㅋ 즐거운 주말되세요
<?
include "connect.php";
$sql_cmt = " select id,name,comment,ip,DATE_FORMAT(wdate,'%Y-%m-%d %h:%i:%s') as date from js_comment where bid = '$number'";
$result_cmt = mysql_query($sql_cmt,$connect);
while($row_cmt=mysql_fetch_array($result_cmt)) {
$str = $row_cmt[comment];
$comment = strip_tags($str,"");
$str = $row_cmt[name];
$name = strip_tags($str,"");
//커멘트 리스트
?>
<?
if($array[row_cmt] < 0 ) {
echo"
<table width=100% border=0 align=center cellpadding=0 cellspacing=0>
<tr bgcolor=#505050 >
<td >
<table width=100%>
<tr >
<td width=100% background='./images/kor_comment_bak.gif' height=32>
<font color=#609060><b><?=$name?></b></font>
<font color=#999999><span style='font-size:11px;'><?=$row_cmt[date]?></span></font>
<a href='javascript:showPassword(<?=$row_cmt[id]?>);'><img src='./images/kor_comment_del.gif' border=0></a></td>
</tr>
</table>
<table width=100%>
<tr>
<td>
<font color=#c2c2c2><?=nl2br($comment)?></font></td>
</tr>
</table><br>
</td>
</tr>
</table>";
}
else {
echo"
<table width=100% border=0 align=center cellpadding=0 cellspacing=0>
<tr bgcolor=#505050 >
<td >
<table width=100%>
<tr >
<td width=100% background='./images/kor_comment_bak.gif' height=32 align=center>
현재 작성된 의견 (코멘트)이 없습니다.</td>
</tr>
</table>
<br>
</td>
</tr>
</table>";
}
?>
라고 나오게 하려하는데... if 문으로 할라했는데... 좀 이상하게 나오네요... 글도 작성이 제대로 안되고.. 작성하면 없다는 코멘트분이 증가하네요.... 부탁드립니다. 염치없이 주말인데 또 들렸네요 ㅋㅋ 즐거운 주말되세요
<?
include "connect.php";
$sql_cmt = " select id,name,comment,ip,DATE_FORMAT(wdate,'%Y-%m-%d %h:%i:%s') as date from js_comment where bid = '$number'";
$result_cmt = mysql_query($sql_cmt,$connect);
while($row_cmt=mysql_fetch_array($result_cmt)) {
$str = $row_cmt[comment];
$comment = strip_tags($str,"");
$str = $row_cmt[name];
$name = strip_tags($str,"");
//커멘트 리스트
?>
<?
if($array[row_cmt] < 0 ) {
echo"
<table width=100% border=0 align=center cellpadding=0 cellspacing=0>
<tr bgcolor=#505050 >
<td >
<table width=100%>
<tr >
<td width=100% background='./images/kor_comment_bak.gif' height=32>
<font color=#609060><b><?=$name?></b></font>
<font color=#999999><span style='font-size:11px;'><?=$row_cmt[date]?></span></font>
<a href='javascript:showPassword(<?=$row_cmt[id]?>);'><img src='./images/kor_comment_del.gif' border=0></a></td>
</tr>
</table>
<table width=100%>
<tr>
<td>
<font color=#c2c2c2><?=nl2br($comment)?></font></td>
</tr>
</table><br>
</td>
</tr>
</table>";
}
else {
echo"
<table width=100% border=0 align=center cellpadding=0 cellspacing=0>
<tr bgcolor=#505050 >
<td >
<table width=100%>
<tr >
<td width=100% background='./images/kor_comment_bak.gif' height=32 align=center>
현재 작성된 의견 (코멘트)이 없습니다.</td>
</tr>
</table>
<br>
</td>
</tr>
</table>";
}
?>
댓글 2
$array 변수는 어디서 온 건가요?
if(mysql_num_rows($row_cmt > 0) {
//코멘트 출력
} else {
// 코멘트 없다는 메시지 출력
}
이렇게 해야할 것 같은데요...
mysql_fetch_array()함수는 하나 하나의 row 값을 받아오는 함수인데 제가 mysql_num_rows로 row가 몇개인지 물어보며.. if문을 썼으니... ㅋㅋㅋ 아무튼 몰라도 좋은점은 해결책을 찾으면 보람있다는 ㅋㅋ 결국 여러군데 지적을 받은곳도 있고해서..
아래처럼 바꿨네요 혹시라도 다른분들도 이런 방식의
코멘트를원할 수도 있으니.. ㅆㅓ놓을게요...
항상 답변주셔서 감사하구요.. 자주들리겠습니다.. ㅋㅋ
$sql_cmt = " 쿼리문.~~
$result_cmt = mysql_query($sql_cmt);
$total = mysql_num_rows($result_cmt);
if($total > 0){
while($row_cmt=mysql_fetch_assoc($result_cmt)) {
$str = $row_cmt[comment];
$comment = strip_tags($str,"");
$str = $row_cmt[name];
$name = strip_tags($str,"");
echo" 이하동문.. ㅋㅋ"'
}
}
else{
echo""'
}