【发布时间】:2013-03-20 23:22:41
【问题描述】:
好吧,我不太擅长 mySQL。
我在这里要做的是加入 2 个表:
1. users
2. comments
我正在尝试创建一个评论系统,它应该从users 表中提取用户名和个人资料图片,并从comments 表中提取 cmets 和 date_posted。
这是我的查询:
$mem_query = mysql_query("SELECT `comments`.`comment_id` AS `comments_id`, `users`.`user_id` AS `users_id`, `users`.`username`,`users`.`profile_pic`,`comments`.`txt_content`,`comments`.`date_posted` FROM `comments` INNER JOIN `users` ON `users`.`user_id` = `comments`.`user_id` WHERE `comments`.`post_id` = '$post_id'");
我想使用 while 循环运行查询:
while($run_mem = mysql_fetch_array($mem_query)){
$comment_id = $run_mem['comments_id'];
$txt_content = $run_mem['comments.txt_content'];
$profile_pic = $run_mem['users.profile_pic'];
?>
//Run all the comments depending upon the post_id.
<?php
}
?>
截至目前,它给了我这个错误: - 这在我的第二次更新后没有显示。
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\simpleblog\view.php on line 73
我该如何解决?谢谢。
P.S:我知道 'mysql_query' 在 PHP 中已被弃用。我稍后会改变它。
P.S 2:我将查询从table.column 修复为table.column,但是,它没有显示任何错误,但它没有从数据库中提取任何信息。
【问题讨论】: