我在这里有一个发布系统,其中一个人单击“|评论”,然后出现一个 div,其中包含以下代码。
<div class="commentbox" id="commentbox<?php echo $_row["id"];?>" style="display:none;"><div style="padding-right:10px;" align="right"><a class="close" href="#" id="<?php echo $_row['id'];?>">X</a></div>
<div class="scroll-pane">
<?php include 'load_comments.php';?>
</div>
<div class="commentupdate" id='commentbox<?php echo $_row["id"];?>'>
<div class="stcommenttext" >
<form method="post" action="">
<textarea name="comment" class="comment" maxlength="200" id="ctextarea<?php echo $_row["id"];?>"></textarea>
<br />
<input type="submit" value=" Comment " id="<?php echo $_row["id"];?>" class="comment_button button"/>
</form>
</div>
</div>
</div>
$_row['id']
是一个 sql 获取数组
加载评论.php
<?php
$commentquery = mysql_query("SELECT * FROM comments WHERE msgid=".$_row['id']."");
$count=mysql_num_rows($commentquery);
if($count!==0)
{
while($commrow = mysql_fetch_array($commentquery))
{
?>
<div class="stcommentbody" id="stcommentbody<?php echo $commrow['msgid']; ?>">
<div class="stcommentimg">
<?php $userdata = mysql_query('SELECT firstname,lastname,Photo FROM users WHERE id="'.$commrow["uic"].'"' );
$userrow = mysql_fetch_array($userdata); ?>
<img src="profile/<?php echo $userrow['Photo']; ?>" class='small_face' alt='<?php echo $userrow['firstname']; echo' ';echo $userrow['lastname']; ?>'/>
</div>
<div class="stcommenttext">
<?php if($commrow['uic']==$uid) { ?>
<a class="stcommentdelete" href="#" id='<?php echo $commrow['msgid']; ?>' title='Delete Comment'></a>
<?php } ?>
<b><a href="profile.php?id=<?php echo $commrow['uic']; ?>"><?php echo $userrow['firstname']; echo' ';echo $userrow['lastname']; ?></a></b> <?php echo $commrow['comment'];?>
<div class="stcommenttime"></div>
</div>
</div>
<?PHP
}
}else{
echo 'Be the first to comment';
}
?>
现在,在单击提交按钮时,将调用以下 ajax,
<script>
$(document).ready(function() {
//Commment Submit
$('.comment_button').on("click",function(){
var ID = $(this).attr("id");
var comment= $("#ctextarea"+ID).val();
var dataString = 'comment='+ comment + '&msgid=' + ID;
if($.trim(comment).length===0)
{
alert("Please Enter Comment Text");
}
else
{
$.ajax({
type: "POST",
url: "comment_ajax.php",
data: dataString,
cache: false,
success: function(html){
$(".scroll-pane").load("load_comments.php");
}
});
}
return false;
});
// commentopen
$('.commentopen').on("click",function()
{
var ID = $(this).attr("id");
$("#commentbox"+ID).slideToggle('fast');
return false;
});
$('.close').on("click",function()
{
var ID = $(this).attr("id");
$("#commentbox"+ID).hide('fast');
return false;
});
});
</script>
ajax 运行良好,评论被插入,但新评论没有被加载,而是错误:
Notice: Undefined variable: _row in C:\wamp\www\fresh\final\load_comments.php on line 4
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\fresh\final\load_comments.php on line 5
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
2 0.0030 154344 mysql_num_rows ( ) ..\load_comments.php:5
( ! ) Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\fresh\final\load_comments.php on line 8
Call Stack
# Time Memory Function Location
1 0.0000 147616 {main}( ) ..\load_comments.php:0
2 0.0040 154472 mysql_fetch_array ( ) ..\load_commen
请帮我更正代码如果不可能,请指导我一个更好的
提前致谢 !