묻고답하기
page_full_width" class="col-xs-12" |cond="$__Context->page_full_width">
게시판에서 코멘트부분에서 코멘트가 없는 경우.....
2006.05.24 05:22
아래의소스는 제가 사용하는 코멘트부분의소스인데요...
코멘트리스트와 입력부로 나누어져있습니다..
제가 if문으로 코멘트가 없을때 는 else~부분의내용을 나타나게 하고싶은데 잘 안되네요...
코멘트가 입력되었으면 입력된 내용이 나타나는. 뭐~~ 그런.. 건데요..
<script language="javascript">
function showPassword(ob){
var x,y;
x = (document.body.offsetWidth-200)/2 + document.body.scrollLeft;
y = (document.body.offsetHeight)/2 + document.body.scrollTop;
document.all.divPasswd.style.top = y;
document.all.divPasswd.style.left = x;
document.all.divPasswd.style.display=""
document.pwForm.id.value=ob;
document.pwForm.passwd.focus();
}
function submit_Passwd()
{
var val = document.pwForm.passwd.value;
if (CheckStr(val, " ", "")==0)
{
alert("패스워드를 입력해 주세요");
document.pwForm.passwd.value="";
document.pwForm.passwd.focus();
return;
}
document.pwForm.submit();
}
function CheckStr(strOriginal, strFind, strChange){
var position, strOri_Length;
position = strOriginal.indexOf(strFind);
while (position != -1){
strOriginal = strOriginal.replace(strFind, strChange);
position = strOriginal.indexOf(strFind);
}
strOri_Length = strOriginal.length;
return strOri_Length;
}
</script>
<html>
<head>
<title>『 L E E J I N S O O .net 』 ™</title>
<meta http-equiv=Content-Type content=text/html;>
<link rel=StyleSheet href='style.css' type='text/css'>
</head>
<body bgcolor=#505050>
<?
include "connect.php";
$sql_cmt = " select id,name,comment,ip,DATE_FORMAT(wdate,'%Y-%m-%d %h:%i:%s') as date from $commentname 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(mysql_num_rows($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=".javascriptshowPassword(<?=$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>";
}
?>
<?
//-- END
}
// 코멘트 입력
?>
<br>
<table width=90% border=0 align=center cellpadding=0 cellspacing=0>
<tr>
<td bgcolor=#505050>
<table width=95% cellpadding=0 cellspacing=0>
<form name=comment_insert method=post action='comment_ok.php'>
<input type=hidden name=bid value='<?=$number?>'>
<tr>
<td><img src="./images/kor_comment_title.gif" border=0></td>
</tr>
<tr>
<td><textarea name=comment rows=7 class=textarea2></textarea></td>
</tr>
</table><br>
<table width=95% cellpadding=0 cellspacing=0>
<tr>
<td height="27" align=right>
이름 : <input type=text name=name size=10 class=input3 align=middle>
비밀번호 : <input type=password name=passwd size=10 class=input3 align=middle>
<input type=image value="등 록" src=./images/kor_view_save.gif border=0 align=middle>
</td>
</tr>
</table>
</form>
</table>
</td>
</tr>
</table>
<!-- 패스워드 창 -->
<div id="divPasswd" style="display:none;position:absolute;">
<form name=pwForm method=post action='+ '+ 'comment_del.php'>
<table border="1" bordercolor="#777777"><tr><td>
<table width=200 cellpadding=0 cellspacing=0>
<tr>
<td bgcolor="#505050" height=32 align="left" style="padding-left:30;">
<font color=#609060>비밀번호</font><font color=#c2c2c2>를 입력하세요.</font>
<img src="./images/kor_comment_del.gif" style="cursor:hand" onClick=".javascriptdocument.all.divPasswd.style.display='none';" WIDTH="10" HEIGHT="10">
</td>
</tr>
<tr>
<td bgcolor="#505050" style="padding-left:10;padding-right:10;padding-bottom:10;padding-top:5">
<input name="passwd" type="password" class=input2>
<input type="hidden" name="bid"size="10" value="<?=$number?>">
<input type="hidden" name="id" size="10" value="">
<img src="./images/kor_comment_del_ok.gif" style="cursor:hand" align="absmiddle" onClick="submit_Passwd(this);" WIDTH="30" HEIGHT="20">
</td>
</tr>
</table>
</td></tr></table>
</form>
</div><!-- 패스워드 창 -->
코멘트리스트와 입력부로 나누어져있습니다..
제가 if문으로 코멘트가 없을때 는 else~부분의내용을 나타나게 하고싶은데 잘 안되네요...
코멘트가 입력되었으면 입력된 내용이 나타나는. 뭐~~ 그런.. 건데요..
<script language="javascript">
function showPassword(ob){
var x,y;
x = (document.body.offsetWidth-200)/2 + document.body.scrollLeft;
y = (document.body.offsetHeight)/2 + document.body.scrollTop;
document.all.divPasswd.style.top = y;
document.all.divPasswd.style.left = x;
document.all.divPasswd.style.display=""
document.pwForm.id.value=ob;
document.pwForm.passwd.focus();
}
function submit_Passwd()
{
var val = document.pwForm.passwd.value;
if (CheckStr(val, " ", "")==0)
{
alert("패스워드를 입력해 주세요");
document.pwForm.passwd.value="";
document.pwForm.passwd.focus();
return;
}
document.pwForm.submit();
}
function CheckStr(strOriginal, strFind, strChange){
var position, strOri_Length;
position = strOriginal.indexOf(strFind);
while (position != -1){
strOriginal = strOriginal.replace(strFind, strChange);
position = strOriginal.indexOf(strFind);
}
strOri_Length = strOriginal.length;
return strOri_Length;
}
</script>
<html>
<head>
<title>『 L E E J I N S O O .net 』 ™</title>
<meta http-equiv=Content-Type content=text/html;>
<link rel=StyleSheet href='style.css' type='text/css'>
</head>
<body bgcolor=#505050>
<?
include "connect.php";
$sql_cmt = " select id,name,comment,ip,DATE_FORMAT(wdate,'%Y-%m-%d %h:%i:%s') as date from $commentname 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(mysql_num_rows($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=".javascriptshowPassword(<?=$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>";
}
?>
<?
//-- END
}
// 코멘트 입력
?>
<br>
<table width=90% border=0 align=center cellpadding=0 cellspacing=0>
<tr>
<td bgcolor=#505050>
<table width=95% cellpadding=0 cellspacing=0>
<form name=comment_insert method=post action='comment_ok.php'>
<input type=hidden name=bid value='<?=$number?>'>
<tr>
<td><img src="./images/kor_comment_title.gif" border=0></td>
</tr>
<tr>
<td><textarea name=comment rows=7 class=textarea2></textarea></td>
</tr>
</table><br>
<table width=95% cellpadding=0 cellspacing=0>
<tr>
<td height="27" align=right>
이름 : <input type=text name=name size=10 class=input3 align=middle>
비밀번호 : <input type=password name=passwd size=10 class=input3 align=middle>
<input type=image value="등 록" src=./images/kor_view_save.gif border=0 align=middle>
</td>
</tr>
</table>
</form>
</table>
</td>
</tr>
</table>
<!-- 패스워드 창 -->
<div id="divPasswd" style="display:none;position:absolute;">
<form name=pwForm method=post action='+ '+ 'comment_del.php'>
<table border="1" bordercolor="#777777"><tr><td>
<table width=200 cellpadding=0 cellspacing=0>
<tr>
<td bgcolor="#505050" height=32 align="left" style="padding-left:30;">
<font color=#609060>비밀번호</font><font color=#c2c2c2>를 입력하세요.</font>
<img src="./images/kor_comment_del.gif" style="cursor:hand" onClick=".javascriptdocument.all.divPasswd.style.display='none';" WIDTH="10" HEIGHT="10">
</td>
</tr>
<tr>
<td bgcolor="#505050" style="padding-left:10;padding-right:10;padding-bottom:10;padding-top:5">
<input name="passwd" type="password" class=input2>
<input type="hidden" name="bid"size="10" value="<?=$number?>">
<input type="hidden" name="id" size="10" value="">
<img src="./images/kor_comment_del_ok.gif" style="cursor:hand" align="absmiddle" onClick="submit_Passwd(this);" WIDTH="30" HEIGHT="20">
</td>
</tr>
</table>
</td></tr></table>
</form>
</div><!-- 패스워드 창 -->
댓글 5
-
Mersia
2006.05.24 11:14
if 문에서 괄호를 안열어 주셨기에 else 문 앞에 괄호를 while 의 종료지점으로 인식하는듯 싶은데요 -
Mersia
2006.05.24 11:15
if(mysql_num_rows($row_cmt > 0) { -
이진수
2006.05.24 13:25
{ 이거는 제가 작성하다가 빠졌네요.. -_- 이것ㄸㅒ문은 아니네요... 그래도 답변감사합니다..
아시는 분 답변좀부탁드릴게요 -
Mersia
2006.05.26 23:09
if(mysql_num_rows($row_cmt > 0) 이것대신에 그냥 코멘트 유무문 체크하시는게...
if($row_cmt) {
요롷게 한번 해보세요 -
이진수
2006.05.28 11:02
답변주셨군요 .. 감사합니다.. 제가 잘못알았네요
ㅋㅋ 어찌어찌해서 해결하게되었네요
mysql_fetch_array()함수는 하나 하나의 row 값을 받아오는 함수인데 제가 mysql_num_rows로 row가 몇개인지 물어보며..당연히 1인데.. ㅋㅋ 그러면서 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""'
}