onthespot Posted July 17, 2009 Share Posted July 17, 2009 Ok so i have a news table and a news comment table. Inside the news comment table, i have made the newsid a foreign key, which was a primary key in the news table. Im unsure about how to linked the two on a page and therefore that will display the comments at the bottom of each news page in php. I should be ok once i understand how to get the two tables working together. Would be helpful if someone could guide me. Link to comment https://forums.phpfreaks.com/topic/166331-solved-2-tables/ Share on other sites More sharing options...
p2grace Posted July 17, 2009 Share Posted July 17, 2009 Two ways: Method 1: SELECT * FROM `news` `n`, `news_comments` `c` WHERE `n`.`newsID` = `c`.`newsID` Method 2: SELECT * FROM `news` AS `n` INNER JOIN `news_comments` AS `c` USING ( `newsID` ) Link to comment https://forums.phpfreaks.com/topic/166331-solved-2-tables/#findComment-877096 Share on other sites More sharing options...
rhodesa Posted July 17, 2009 Share Posted July 17, 2009 When displaying a news item, you should know the id of it. Then, just select the comments for it: SELECT * FROM news_comments WHERE newsid = '$newsid' Link to comment https://forums.phpfreaks.com/topic/166331-solved-2-tables/#findComment-877097 Share on other sites More sharing options...
onthespot Posted July 17, 2009 Author Share Posted July 17, 2009 cheers for the replies, rhodes that really makes sense. Link to comment https://forums.phpfreaks.com/topic/166331-solved-2-tables/#findComment-877101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.