海我試圖做一個評論系統使用PHP和MySQL(沒有jQuery或AJAX) 問題是如何找到帖子的用戶名的ID我用了一個while循環爲它發佈到所有帖子到目前爲止,我在這裏.....如何查詢獲取特定的帖子ID?
//user data is set
if (isset($_POST['comment'])) {
//variables to post in database
$comment = $_POST['comment'];
$com_from = $_SESSION['user'];
$com_to = $_GET['u'];
$com_time = date("Y-m-d H:i:s");
$u = $_GET['u'];
//query to get the id of the post in the `post` table
$que = mysql_query("SELECT * FROM posts WHERE `post_to` = '$u'");
if ($que) {
//loop through all the posts ad get all ID
while ($ro = mysql_fetch_array($que)) {
$pst_id = $ro['post_id'];
//query inside the while loop for getting the post ID i think here is the problem
if (!empty($_POST['comment'])) {
$com_query = mysql_query("INSERT INTO comments SELECT '','$comment',`post_id`,'$com_from','$com_to','$com_time' FROM `posts` WHERE `posts`.`post_id` = $pst_id");
}
}
}
}
什麼是'$ u'和'$ com_to'? –
您提供的代碼和評論不可讀。 –
@HamedKamrava $ u是$ _GET ['u'],其中url是profile.php?u =用戶名和$ com_to對用戶發表評論(意味着用戶的帖子所在的位置) –