Guys im trying to create a commenting system for a blog. In that i have the problem of not able to make the comments stick to its original posts, as the comments seem to loop in to all the posts where there was no comments posted.Any advice would be helpful.
Here is the code for the script where the posts and comments are made to print:
<?php
$status2view=$project->statusView($_SESSION['uname']);
foreach($status2view as $row){
$sql1="select * from updates,comment_update where comment_update.os_id like updates.update_id and comment_update.type like 'b'";
$stmth=$conn->prepare($sql1);
$stmth->bindparam(":either",$_SESSION['uname']);
$stmth->bindparam(":statusid",$status_id);
$stmth->execute();
$status_reply= $stmth->fetchAll(PDO::FETCH_ASSOC);
?>
</div>
Remove X";
}
$status_replies="";
$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='';
//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>';
}
if ($reply_osid==$updateid) {
$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>';
} else {
$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>';
$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;
}
}
?>
here are the class methods:-
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 && type='b' order by time asc");
$stmth->bindparam(":statusid", $updateid);
$stmth->execute();
return $stmth->fetchAll(PDO::FETCH_ASSOC);
}
catch (Exception $exc){
echo $exc->getMessage();
}
}
note that the user can make posts only in the type "a" &"c" while other users can make the comments as type 'b'. all the values are based in the same table called 'updates'(os_id is called original status id).
here is a screenshot of how my db is like:

0 comments:
Post a Comment