海我试图做一个评论系统使用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对用户发表评论(意味着用户的帖子所在的位置) –