我想标识每个评论,以便任何成员对评论的评论,INSERT和SELECT知道在哪里显示评论,评论谁在评论和在什么评论。这就像为每个评论创建一个ID,以便SELECT在每个消息的位置显示每条消息。 BU我不知道这是一个HTML,PHP或JavaScript问题来处理。 jsfiddle是here。想知道这是一个HTML,PHP或JavaScript问题
PHP
我挑中的URL字符串
$id = $_GET['id']; // this id of the user being commented in the user table I guess I will need that id to identify which user is being commented "profile" that's the id of his profile
if (isset($_SESSION['id'])) {
$userid = $_SESSION['id'];
$username = $_SESSION['name']; }
else {
// do this
}
// the userid contains the id and name of the user commenting "the user logged in".
if ($_POST['comment_field_1'] != ""){
$comment_field_1 = $_POST['comment_field_1'];
$comment_field_1 = stripslashes($comment_field_1);
$comment_field_1 = strip_tags($comment_field_1);
$comment_field_1 = mysql_real_escape_string($comment_field_1);
$comment_field_1 = eregi_replace("'", "'", $comment_field_1);
$sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,parent_id, message_date)
VALUES('$userid','$idc','$comment_field_1', $parent_id now())")
or die (mysql_error());
// i guess the $parent_id should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment.
}
// men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc...
if ($_POST['comment_field_2'] != ""){ // responses form field
$comment_field_2 = $_POST['comment_field_2'];
$comment_field_2 = stripslashes($comment_field_2);
$comment_field_2 = strip_tags($comment_field_2);
$comment_field_2 = mysql_real_escape_string($comment_field_2);
$comment_field_2 = eregi_replace("'", "'", $comment_field_2);
$sql = mysql_query("INSERT INTO comments (mem_id,commented_men_id, the_message,sub_commented_id, message_date)
VALUES('$userid','$idc','$comment_field_1', $sub_commented_id now())")
or die (mysql_error());
// here instead of $parent_id I use field created for responses to tag a comment as a response should be initialize somewhere in the top with a value of 0 or 1 depending weather it is a response or a comment. I am not sure weather I should leave the parent_id variable or come with this new field $sub_commented_id. What do you think?
}
// men_id is the field of the $userid, commented_men_id is the field for the commented on, $idc variable etc...
if (isset($_SESSION['id'])) {
if ($_SESSION['id'] == $userid) {
$the_message_form = '
comment (220 char max)
<form align="left" id="comment" action="profile.php?id='.$idc.'" method="post" enctype="multipart/form-data" name="message_from">
<textarea type="text" id="text1" name="comment_field_1" rows="3" style="width:97%;"></textarea>
<input class="commentinput" name="submit" type="button" value="submit comment" align="left" />
</form>';
}
}
$sql1 = mysql_query("SELECT id, mem_id, commented_men_id, the_message,parent_id, message_date FROM comments WHERE commented_men_id='$idc' ORDER BY message_date DESC LIMIT 20")or die (mysql_error());
$i = 0;
while($row = mysql_fetch_array($sql1)){
$j = $i++;
$message_id = $row["id"];
$uid = $row["mem_id"];
$the_message= $row["the_message"];
$message_date = $row["message_date"];
$message_date = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($message_date));
$sql_mem_data = mysql_query("SELECT id, name FROM users WHERE id='$uid' LIMIT 1");
while($row2 = mysql_fetch_array($sql_mem_data)){
$uid = $row2["id"];
$ufirstname = $row2["name"];
$ufirstname = mb_strimwidth($ufirstname, 0, 20, '…');
}
$messageDisplayList .= '
<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em">
<tr>
<td width="auto" height="auto" bgcolor="#EFEFEF" style="vertical-align:top"><a width="auto" height="auto" title="'.$row2["name"] .' "href="profile.php?id='.$uid .'&name='.$row2["name"].'">' .$user_pic. '</a><br />
</td>
<td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid.'">' . $ufirstname . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date . '</span><br />
<p id="only"> ' . $the_message . '</p><span class="comment">•<a style="padding-left:3.5px; color:#0099ff" href ="">Comment</a></span><div class="commentForm"><form align="left" id="bring" action="profile.php?id='. $uid .'" method="post" enctype="multipart/form-data" name="message_from">
<textarea name="comment_field_2" type="text" id="text2" rows="3" style="width:100%; height:30px;"></textarea>
<input id="bringinput" name="submit" type="button" value="submit" align="left" />
</form></div>
</td>
</tr>
</table> <br/>';
}
$sql_sub_coment = mysql_query ("SELECT id, mem_id, commented_men_id, sub_commented_id, the_message, message_date FROM comments WHERE sub_commented_id='$blabid3' AND sub_commented_id != 0 ORDER BY blab_date DESC LIMIT 20");
while($row3= mysql_fetch_array($sql_sub_coment)){
$$message_id3 = $row3_sub["id"];
$uid3 = $row3_sub["mem_id"] ;
$the_message3 = $row3_sub["the_message"];
$message_date3 = $row3_sub["message_date"];
$message_date3 = strftime("%b %d, %Y, %Y %I:%M:%S %p", strtotime($blab_date3));
$sql_mem_data = mysql_query("SELECT id, name FROM user WHERE id='$uid3' LIMIT 1");
while($row4 = mysql_fetch_array($sql_mem_data)){
$uid4 = $row4["category_id"];
$ufirstname2 = $row4["name"];
$ufirstname2 = mb_strimwidth($ufirstname2, 0, 20, '…');
}
$$messageDisplayList2 .= '<table width="100%" align="center" cellpadding="4" bgcolor="#CCCCCC" style="margin-bottom:0.5em">
<tr>
<td width="auto" height="auto" bgcolor="#FFFFFF"><a width="auto" height="auto" title="'.$row3["name"] .' "href="profile.php?category_id='.$uid4 .'">' .$blabber_pic2. '</a><br />
</td>
<td width="93%" bgcolor="#EFEFEF"><a href="profile.php?id='.$uid4.'">' . $ufirstname2 . ' </a> • <span style="font-size:10px; font-weight:bold; color:#A6A6A6;">' . $message_date3 . '</span><br /><p id="submessage">' . $the_message3 . '</p>
</td>
</tr>
</table>';
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="style/style.css" type="text/css" media="screen" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".commentForm").hide();
$(".comment").bind('click', function(){
$(this).nextAll(".commentForm:first").slideToggle();
return false;
});
var html = $("#text1").html();
$(".blabinput").click(function() {
console.log("AJAX EVENT OCCURED")
$.post($('#comment').attr("action"),
$("#comment").serialize(),
function(html) {
// Find the first table after the form in the HTML from the server and append it to the form on the page.
$(html) .find('form + table').insertAfter('#comment').after('<br />');
});
});
var html2 = $("#text2").html();
$(".bringinput").click(function() {
console.log("AJAX EVENT OCCURED")
$.post($('#bring').attr("action"),
$("#bring").serialize(),
function(html2) {
// Find the first table after the form in the HTML from the server and append it to the form on the page.
$(html2) .find('form + table').insertAfter('#bring').after('<br />');
});
});
});
的ID这是我到目前为止所。父表单的第一种形式是使用id #message的jquery进行提交和发布,然后第二种形式的id或响应形式的#bring id无法正常工作,它插入但将注释发布到p标签中仅用id,这就是父注释发布的地方,而不是响应评论表单。它应该在下面发布,但不知何故,我有HTML和jQuery的混乱。在那里需要帮助。
评论文字滑动切换,但第二次点击时,意味着有时它不会在第一次点击时切换。但现在的主要问题是获取下面显示的响应和Ajaxing而不刷新浏览器。
如果你也发布你的PHP,它可能会有所帮助。我看到的第一个问题:你有两个元素相同的ID:
... – 2011-05-25 18:53:41
卢克你是在正确的方向我认为我应该创建一个计数器来为每次发表评论后生成一个不同的ID号。但是现在每个评论中都有一个不同的id,那么我该如何使用它呢? – fello 2011-05-25 19:18:07