如何在相关帖子中显示评论

时间:2015-11-02 14:17:11

标签: php pdo comments

伙计我正在尝试在我的示例网站中实际创建一个评论系统(用于教育目的)。但是我现在面临的问题是它没有像预期的那样工作,id为116的帖子的评论显示所有帖子。但是应该仅显示id为116的状态。我创建了post系统,只将类型“**a**”or “**c**”和注释“b”插入到mysql中。但是所有帖子的评论都会出现,无论我在哪里发表评论都会显示所有帖子。任何帮助将不胜感激。

以下是具有post逻辑的代码:

<?php
include '../includes/dbconfig.inc.php';

$status2view=$project->statusView($f_uname);

    foreach($status2view as $row){
           //print_r($row);
           $updateid=$row['update_id'];


//gives output on var_dump


        $status_reply_=$project->reply2StatusView($updateid);


        foreach ($status_reply_ as $row) {

            $status_reply_id=$row['update_id'];
                $reply_author=$row['author'];
                $reply_d=htmlentities($row['update_body']);
                $reply_data=  stripslashes($reply_d);
               $reply_osid=$row['os_id'];
               $account_name=$row['account_name'];
               $reply_date=$row['time'];
               $reply_delete_button="";
               if ($reply_author==$session_uname || $account_name==$session_uname) {
                   $reply_delete_button="<li><span id='$status_reply_id' class='delete_reply_btn glyphicon glyphicon-remove'><a href='#' title='Delete this comment'>Remove X</a></span></li>";
               }
               if ($reply_osid!=$updateid) {

               $status_replies.=""; 

            }  else {

              $status_replies.="<div  class='replyboxes pull-left reply_".$status_reply_id."'><b>Reply by:-<a href='search_results.php?u=".$reply_author."'>".$reply_author."</a>"
                      . "<span class='pull-right'>".$reply_date 
                       . "<b class='caret'>
                         <small><span class='btn-xs btn-danger dropdown-toggle pull-right' data-toggle='dropdown' aria-expanded='true' ><span class='glyphicon glyphicon-edit'></span>
                        <ul class='dropdown-menu'>".$reply_delete_button
                      . "<li><a href='#' class='hidden_text_area glyphicon glyphicon-pencil reply_".$status_reply_id."' title='Edit this comment' >Edit</a></li>"
                      . "<li><a href='report.php?u='".$reply_author."'>Report</a><li></ul>"
                      . "</span></span></small></b><br><legend>".  html_entity_decode($reply_data)."</legend><br></div>";


            }
        }
}       
     foreach ($status2view as $row1) {

         //got values here.
                $updateid=$row1['update_id'];
                $account_name=$row1['account_name'];
                $os_id=$row1['os_id'];
                $author=$row1['author'];
                $post_date=$row1['time'];
                $title= stripslashes($row1['title']);
                $data= stripslashes($row1['update_body']);
                $statusdeletebutton='';
                //insert_status_ui script to get message.

                if($isowner=="yes"){
 $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_session session_editor".$updateid." jumbotron'>"
            . "<a href='#' type='".$updateid."' class='pull-right close_edit' title='Close without editing'>Close X</a>"
            . "<input type='text' class='form-control title_s_edit title_s_".$updateid."' name='status_title' value='".html_entity_decode($title)."' placeholder='Title' >"
            . "<span>&nbsp;</span>"
            . "<textarea id='wall_edit_1' type='".$updateid."' rows='5' cols='50'  class='session_edit text_value_".$updateid."' wrap='hard' placeholder='whats up ".$session_uname."'>
             ".html_entity_decode($data)."</textarea><br>"
            . "<button style='float:right;' value='".$updateid."' type='a' class='btn btn-warning btn btn-large btn-lg post-s-edit'>Update</button></div>" ;


}
 elseif ($is_friend==TRUE&&$session_uname!=$f_uname) {


     $statusui_edit="<div type='".$updateid."' class='hidden_edit_4_friend friend_editor".$updateid." jumbotron'>"
             . "<a title='Close without editing' type='".$updateid."' href='#' class='pull-right close_edit_f'>Close X</a>"
               . "<input type='text' class='form-control title_f_edit title_f_".$updateid."''  name='status_title' value='".html_entity_decode($title)."' placeholder='Title'><br>"
               . "<div>&nbsp;</div>"
            . "<textarea id='wall_edit_2' value='' type='".$updateid."' rows='5' cols='50'  class='friend_edit update_friend_".$updateid."' placeholder='hi ".$session_uname." want to say something to ".$f_uname.". '>"
               .html_entity_decode($data)."</textarea><br>"
               . "<button style='float:right;' value='".$updateid."' type='c' class='btn btn-warning btn-large btn-lg post-f-edit'>Update</button></form></div>";
 }

                if ($author==$session_uname || $account_name==$session_uname) {
                $statusdeletebutton='<li>'
                           . '<a href="#" type="'.$updateid.'" class="delete_4_session hidden_text_delete_'.$updateid.' glyphicon glyphicon-trash delete_reply_btn" title="Delete this status and its replies">Remove</a></li>';
                }
                if($isowner=="yes"){
                $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.'  jumbotron">'
                        . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">'
                        . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3>'
                        . '<span class="pull-right">'
                        . '<div class="dropdown">'
                        . '<button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown"  >'
                        . '<span class="glyphicon glyphicon-edit"></span></button>'
                        . '<ul class="dropdown-menu">'
                        . '<li><a href="#" attr="'.$updateid.'" type="'.$updateid.'" class="edit_4_session hidden_text_edit glyphicon glyphicon-pencil" title="Edit this status" >Edit</a></li>'.$statusdeletebutton.'</ul></div></span><br><hr>'
                        . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">'
                        . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u='.$author.'">'.$author.   '</a>   '.$post_date.'</small></b>'
                        . '<br><p>'.$status_replies.'</p><br>';

                if ($is_friend==TRUE||$session_uname==$f_uname) {
                    $status_list.= '<textarea id="'.$updateid.'"  class="status_reply_'.$updateid.' input-custom2" placeholder="comment\'s"></textarea>'
                            . '<button id="reply_btn_'.$updateid.'" attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>';
                    }

                    }elseif ($is_friend==TRUE&&$session_uname!=$f_uname) {
                    $status_list= $statusui_edit.'<div attr="'.$updateid.'" type="'.$updateid.'" class="statusboxes status_'.$updateid.'  jumbotron">'
                        . '<h3 style="color:black; margin-bottom:5px; margin-top:5px;" class="pull-left">'
                        . '<div id="'.$updateid.'" class="title_s_2copy" value="'.html_entity_decode($title).'">'.html_entity_decode($title).'</div></h3><br><hr>'
                        . '<legend><span class=" data_s_2copy" type="'.$updateid.'" value="'.html_entity_decode($data).'">'
                        . html_entity_decode($data).'</span><br><br></legend><b style="text-align:right; color:black;"><small>Posted by:-  <a href="search_results.php?u='.$author.'">'.$author.   '</a>   '.$post_date.'</small></b>'
                        . '<br><p>'.$status_replies.'</p><br>';
                             $status_list.= '<textarea id="'.$updateid.'"  class="status_update input-custom2" placeholder="comment\'s"></textarea>'
                            . '<button id="reply_btn'.$updateid.'"  attr="'.$updateid.'" type="b" class="btn btn-warning pull-right btn-sm reply_btn reply_'.$updateid.'">Reply</button></div>';


                }
                echo $status_list;
                }  

这是类方法:

   public function statusView($f_uname) {
        $sql="select * from updates where account_name=:either and type='a' or account_name=:either and type='c' order by time desc limit 20";
        $stmth=$this->_db->prepare($sql);
        $stmth->bindValue(":either",$f_uname);
        $stmth->execute();
        return $stmth->fetchAll(PDO::FETCH_ASSOC);

    }
    public function reply2StatusView($updateid){
        try{
        $stmth=  $this->_db->prepare("select * from updates where os_id=:statusid and type='b' order by time asc");
        $stmth->bindparam(":statusid", $updateid);
        $stmth->execute();
     return $stmth->fetchAll(PDO::FETCH_ASSOC);
        }
 catch (Exception $exc){
    echo $exc->getMessage();
        }
        }

0 个答案:

没有答案