Jump to content

selecting from 2 databases at once


jwk811

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/202667-selecting-from-2-databases-at-once/
Share on other sites

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'";

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 =]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.