jwk811 Posted May 23, 2010 Share Posted May 23, 2010 SELECT * FROM tbl_comments WHERE the post they commented is a post from the user the table tbl_comments has just the post_id of the post they are commenting the tbl_posts has the user_id of the person who made the post. PLEASE HELP i know theres a way to select them at the same time i just never understood it. Quote Link to comment https://forums.phpfreaks.com/topic/202667-selecting-from-2-databases-at-once/ Share on other sites More sharing options...
jcbones Posted May 23, 2010 Share Posted May 23, 2010 2 different databases? OR 2 different tables? Your post has 3 tables. $sql = "SELECT a.*,b.title,c.user FROM tbl_comments AS a LEFT JOIN tbl_posts AS b ON a.post = b.id LEFT JOIN user AS c ON c.id = b.user WHERE c.username = 'jwk811'"; Quote Link to comment https://forums.phpfreaks.com/topic/202667-selecting-from-2-databases-at-once/#findComment-1062303 Share on other sites More sharing options...
jwk811 Posted May 23, 2010 Author Share Posted May 23, 2010 yes tables and its actually 2 tables. the post table has the user id in it already. and i dont understand how that works: $sql = "SELECT a.*,b.title,c.user FROM tbl_comments AS a LEFT JOIN tbl_posts AS b ON a.post = b.id LEFT JOIN user AS c ON c.id = b.user WHERE c.username = 'jwk811'"; thank you for your help though, i will go from there =] Quote Link to comment https://forums.phpfreaks.com/topic/202667-selecting-from-2-databases-at-once/#findComment-1062342 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.