|
 |
|
ต้องการสร้างเงื่อนไขให้เจ้าของบทความสามารถลบได้ทุกคอมเม้น |
|
 |
|
|
 |
 |
|
1.ผมต้องการให้เจ้าของบทความสามารถลบทุกคอมเม้นในเรื่องของตนเองได้ แสดงปุ่ม 3 จุด ในทุกคอมเม้นของบทความตนเอง
2.เมื่อตัวเองไปคอมเม้นเรื่องอื่นจะแสดงปุ่ม 3 จุดที่คอมเม้นตนเองเพื่อลบหรือแก้ไขคอมเม้นตัวเอง
แต่จะไม่แสดงปุ่ม 3 จุดที่ไม่ใช่คอมเม้นของตนเอง
ตอนนี้ที่ผมทำได้คือ แสดงปุ่ม 3 จุด (จัดการลบหรือแก้ไขคอมเม้นตนเอง)ในคอมเม้นตัวเองที่ได้คอมเม้นในเรื่องนั้น ๆ ได้


Code (PHP)
$query = "SELECT user.user_id , content.content_id , comment.comment_id , comment.comment , comment.comment_status ,
comment.created_datetime , user.image , user.displayed_name FROM comment
LEFT JOIN user ON comment.user_id = user.user_id
LEFT JOIN content ON content.content_id = comment.content_id
LEFT JOIN chapter ON chapter.chapter_id = comment.chapter_id
WHERE content.content_id = '" . $_GET['post'] . "' AND comment.chapter_id IS NULL
ORDER BY comment.comment_id DESC";
$result = $con->query($query);
$output = '';
$btn_delete = '';
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
// เงื่อนไขจัดการ ลบ/แก้ไข คอมเม้นของตัวเองได้
if(isset($_SESSION['id']) && $_SESSION['id'] == $row['user_id'] ){
$btn_delete .= ' <div class="dropdown d-inline" style="cursor:pointer">
<span class="float-end " data-bs-toggle="dropdown" aria-expanded="false" ><i class="fas fa-ellipsis-v"></i></span>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<li><a class="dropdown-item update" href="#" data-id=' . $row["comment_id"] . '>แก้ไข</a></li>
<li><a class="dropdown-item delete" href="#" data-id=' . $row["comment_id"] . '>ลบ</a></li>
</ul>
</div>';
}else{
$btn_delete .= '';
}
// เช็ครูปภาพ
if(!empty($row['image'])){
$img = $row['image'];
}else{
$img = 'bg1.jpg';
}
// เช็ค session ถ้าไม่มีการ login
if(isset($_SESSION['id'])){
$btn_reply = '<button class="btn btn-primary text-white reply_btn" data-id=' . $row["comment_id"] . ' >ตอบกลับ</button> ';
}else{
$btn_reply = '<button class="btn btn-primary text-white reply_btn_noid" data-id=' . $row["comment_id"] . ' >ตอบกลับ</button> ';
}
if( $row['comment_status'] !== 'ถูกระงับ'){
$output .= '<div class="reply_box ">
<div class="card mt-3">
<div class="card-header">
<img src="upload/content/'.$img.'" width="50" height="50" class="rounded-circle" style="ojective:contain" alt='.htmlspecialchars($row["displayed_name"]).'>
<h6 class=" d-inline " style="color : #620000">' . htmlspecialchars($row["displayed_name"]) . '
</h6> <span class="time">' . thai_date_short_number(strtotime($row['created_datetime'])) . '</span>
'.$btn_delete.'
</div>
<div class="card-body">
<span class="para">' . $row["comment"] . '</span>
</div>
<div class="card-footer bg-white text-end">
'.$btn_reply.'
</div>
</div>
</div>';
}else{
$output .= ' <div class="reply_box ">
<div class="card mt-3">
<div class="card-header">
<h5>***ความคิดเห็นนี้ถูกระงับเนื่องจากมีเนื้อหาที่ไม่เกี่ยวข้องหรือไม่เหมาะสม***</h5>
</div>
</div>
</div>
</div>';
}
$output .= get_reply_comment($con, $row["comment_id"]);
}
echo $output;
Tag : PHP, MySQL, Ajax, jQuery

|
|
 |
 |
 |
 |
Date :
2021-10-23 18:52:37 |
By :
ทาเคชิ |
View :
431 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำได้แล้ว
สร้างเงื่อนไขมาเพื่อเช็คว่าเรื่องนี้ตรงกับของใคร
Code (PHP)
if(isset($_SESSION['id'])){
$query2 = "SELECT content.content_id ,user.user_id FROM content
INNER JOIN user ON user.user_id = content.user_id WHERE content.user_id = '".$_SESSION['id']."'";
$result2 = $con->query($query2);
$row2 = $result2->fetch_assoc();
}
f(isset($_SESSION['id']) && $row2['content_id'] == $_GET['post'] ){
$btn_delete .= ' <div class="dropdown d-inline" style="cursor:pointer">
<span class="float-end " data-bs-toggle="dropdown" aria-expanded="false" ><i class="fas fa-ellipsis-v"></i></span>
<ul class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<li><a class="dropdown-item delete" href="#" data-id=' . $row["comment_id"] . '>ลบ</a></li>
</ul>
</div>';
}
|
 |
 |
 |
 |
Date :
2021-10-24 14:12:42 |
By :
methus.phon |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|