guys i'm trying to create a commenting system to posts in a example site. And i can't seem to print the exact comments to its original post. i created two tables updates and comment_update and kept os_id as the common table row, where it is refering to update_id of updates table. everything seems ok except for the loops which is screwing up the output. Any advice on how to rectify it as i tried with while & other loops everything gives the same problem.
here is my code for that logic:
<?php
$status_replies="";
$statusui_edit="";
$status2view=$project->statusView($_SESSION['uname']);
foreach($status2view as $row){
$updateid=$row['update_id'];
$account_name=$row['account_name'];
$os_id=$row['os_id'];
$author=$row['author'];
$post_date=$row['time'];
$title= stripslashes($row['title']);
$data= stripslashes($row['update_body']);
$statusdeletebutton='';
$sql1="select * from updates,comment_update where comment_update.os_id like updates.update_id and comment_update.type like 'b'";
$sql2="select * from updates left join comment_update using (os_id) where comment_update.os_id=:statusid limit 1 ";
$stmth=$conn->prepare($sql2);
// $stmth->bindparam(":either",$_SESSION['uname']);
$stmth->bindparam(":statusid",$updateid);
$stmth->execute();
$status_reply= $stmth->fetchAll(PDO::FETCH_ASSOC);
foreach ($status_reply as $row1) {
$status_reply_id=$row1['comment_id'];
$reply_author=$row1['author'];
$reply_d=htmlentities($row1['comment_body']);
$reply_data= stripslashes($reply_d);
$reply_osid=$row1['os_id'];
$reply_date=$row1['time'];
$reply_delete_button="";
if ($reply_author==$_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 ($updateid==$reply_osid) {
$status_replies.="";
} else {
$status_replies.="";
}
//insert_status_ui script to get message.
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>';
}
$status_list= $statusui_edit.''
. ''
. ''.html_entity_decode($title).'</h3>'
. '<span class="pull-right">'
. ''
. ''
. ''
. '</span><br><hr>'
. '<legend><span class=" data_s_2copy" type="'.$updateid.'" >'
. 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="reply_textarea_'.$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>';
}
echo $status_list;
}
0 comments:
Post a Comment