0

I have searched on this site and can't see anything obvious that I have done wrong, but my query isn't working and is returning the Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in error

$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";
user2571547
  • 91
  • 1
  • 1
  • 9

2 Answers2

1

First join all tables, then add your where condition

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'
juergen d
  • 195,137
  • 36
  • 275
  • 343
0

Try in phpmyadmin and then copy paste it into php code, you don't need worry about wrong query when use it in PHP.

Killer Whale
  • 87
  • 2
  • 12