想知道这是html,php还是javascript问题

问题描述

|| 我想为每个评论添加ID,以便在任何成员对评论进行评论的情况下,INSERT和SELECT都知道在哪里显示评论,谁在评论中以及在什么评论评论。这就像为每个注释创建一个ID,以便SELECT在其位置显示每个消息。但是我不知道这是要处理的html,PHP还是javascript问题。 jsfiddle在这里。 的PHP 我确实在网址字符串中选择了ID
 $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,sub_commented_id,$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,$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,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,20,\'&hellip;\');


    }

            $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> &bull; <span style=\"font-size:10px; font-weight:bold; color:#A6A6A6;\">\' . $message_date . \'</span><br />
  <p id=\"only\">    \' . $the_message . \'</p><span class=\"comment\">&bull;<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,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,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,\'&hellip;\');

}
            $$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> &bull; <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为#message的jquery进行提交和发布,然后第二个表单的ID的#bring id或响应表单无法正常工作,它正在插入但在p标签中发布了注释仅具有ID。那是父注释而不是响应注释表单的位置。它应该在下面发布,但是,以某种方式我将html和jquery弄乱了。在那里需要帮助。 评论文本正在滑动切换,但是第二次单击,这意味着有时我第一次单击时不会切换。但是现在的主要问题是,在不刷新浏览器的情况下,使响应表单显示在下方,并且Ajaxing。     

解决方法

您将需要修改保存您的注释的数据库表,以添加\“ parent \”列。顶级注释的父ID为0,这意味着它不是对任何其他注释的响应。 响应将在其父列中具有顶级注释的ID。 修改表格后,您将需要修改PHP代码以识别对顶级注释的响应,并修改HTML以正确显示它们。