-2
我想做一個像評論部分的Facebook,用戶可以在主頁的特定帖子發表評論。問題是,如果我嘗試在一篇文章中發表評論,那麼評論就會捲入所有帖子。這裏的形象:php Facebook like評論部分
這裏是PHP代碼
$get_posts = "SELECT * FROM science_post WHERE user_id ORDER by 1 DESC LIMIT 5";
$run_posts = mysqli_query($conncate, $get_posts);
while ($row_posts = mysqli_fetch_array($run_posts)) {
/** .. Some other code .. ***/
$user_com = $_SESSION['sess_user'];
$get_com = "select * from users where user_name='$user_com'";
$run_com = mysqli_query($conn, $get_com);
$row_com = mysqli_fetch_array($run_com);
$user_com_id = $row_com['user_id'];
$user_com_name = $row_com['user_name'];
if (isset($_POST['submit_co'])) {
if (!empty($_POST['comment_co'])) {
$comment = $_POST['comment_co'];
$insert = "insert into science_comment (post_id,user_id,comment,comment_author,date) values ('$post_id','$user_com_id','$comment','$user_com_name', NOW())";
$run = mysqli_query($conncate, $insert);
} else {
echo "<script> alert('Please enter a answer before submitting.')</script>";
}
}
感謝您的答覆,但問題是,它在數據庫表的循環,以及。在science_comment表中,我有10條評論與不同的評論ID和帖子ID。 –