This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
                                
                                    (32个答案)
                                
                        
                                6年前关闭。
            
                    
我在该站点上进行了搜索,看不到任何明显的错误说明,但是我的查询无法正常工作,并返回警告:mysql_fetch_array()期望参数1为资源,布尔值错误给出

$sql2 = "SELECT users.user_id, users.username, users.profile, post_id, post_content, post_date, post_topic, post_by, topics.category, topic.sub_category
    FROM `posts`
    JOIN `users` on posts.post_by = users.user_id WHERE post_topic='$id'
    JOIN `topics` on posts.post_topic = topics.topic_id";

最佳答案

首先join所有表,然后添加您的where条件

SELECT u.user_id, u.username, u.profile,
       p.post_id, p.post_content, p.post_date, p.post_topic, p.post_by,
       t.category, t.sub_category
FROM `posts` p
JOIN `users` u on p.post_by = u.user_id
JOIN `topics` t on p.post_topic = t.topic_id
WHERE p.post_topic='$id'

10-05 19:10