add reply to a comment system that using jquery and php -


i trying create commenting system uses facebook. use php , jquery. code works perfect. want add reply system in it. idea how this?

this main page: wall.php

<script>    $(document).ready(function(){                              $("#comment_process").click(function(){    if($("#comment_text").val() != ""){      $.post("comments.php?action=post", { comment: $("#comment_text").val() }, function(data) {         $(".comments").html(data);         $("#comment_text").val("");      });     }    });     });    </script>  <div class="comment_container"> <div class="comment_form">  <textarea id="comment_text" ></textarea> <input type="button" id="comment_process" value="post"/>  </div> </div>  <div class="comments">  <?php include_once("comments.php");?> </div>  ?> 

and comments.php

<?php  function getcomments(){ $comments = "";     // use desc order date in order display comments date     $sql = mysql_query("select * comments order comment_date desc ") or die (mysql_error());      if(mysql_num_rows($sql) == 0){             $comments = " <div class='each_comment'> there no comments ...</div> ";     }else{         while ($row= mysql_fetch_assoc($sql)){                       $comments .= "says : <div class='each_comment'>  <small><em> ".$row['comment_date']." </em></small><br />".$row['comment']."</div> </br>";          }     }     return $comments;   }   function postcomments($comment){      $comment = mysql_real_escape_string(strip_tags($comment));      $sql = mysql_query(" insert `comments` (comment, comment_date) values ('".$comment."', now()) ");     return true; }  if((isset($_get['action'])) && ($_get['action'] == "post")) {     postcomments($_post['comment']); }  echo getcomments(); ?> 

orbling has right. let me show did blog site working on in asp.net mvc , maybe others in future.

i have 2 classes named article , comment , have following properties in php remember. little rusty on php

class article {  public $article_id; public $user_id; public $article_date; //... more properties, ctors, methods }  class comment { public $comment_id; public $article_id; public $isroot; public $parent_id; public $comment_date; public $content; //... more properties, ctors, methods } 

then user similar constructed:

    function getcomments($article_id){ $str = ""; // should put comment in order date still have separate //comments replies add additional nest foreach loop following if //statement inside main foreach loop. happen newest/oldest comment //will first 1 appended string , go inner foreach //loop see if $parent_id = $comment_id , if append string. //i have different div class replies indented. may not //practical way, considering articles going have less 1000 //comments if lucky wont bad. $q = $this->db->query("select * comments article_id = $article_id order comment_date desc") or die (mysql_error());          if($q->num_rows() > 0):             foreach($q->result() $row):                 if($row->isroot && $row->parentid = null):                 // here append $str create div container                      //for each comment root comment. included user avatar, user link, date //create, content, , on bottom of div have <span>expand replies</span> , //<span>reply<span> use jquery toggle replies on , off etc.                 // same thing here cycle through $q find //comments parent_id equal comment_id of $row //they ordered date. cool thing create array of reply , change order maybe want newest comments on top oldest replies on //top or should below parent comment                 foreach($q->result() $row2):                    if($row->comment_id = $row2->parent_id)                     // same thing except html format reply (eg: indent div)                    endif;                 endforeach;             endforeach;             }         else:             $str = "<div class='each_comment'> there no comments ...</div> ";         endif;           echo htmlentities($str);      } 

then have use jquery/javascript orbling suggests: show(); hide(); replies , use function such slidedown(parent_id); once reply button hit <div> container appears below parent comment.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -