saeed_violinist Posted June 29, 2010 Share Posted June 29, 2010 Hi! I really got confused about this, I am trying to make an article system. if it was 1 author fore each article it was not a problem. These articles may have only one or multiple authors each. here is my example tables. I really appriciate if you show any approach tho handle this. I seted up tables like this: table articles : ---------------------------------------- article_id | title | content | authors ---------------------------------------- 0 | test | blahblah | 1,2 1 | test2 | blahblah | 1,2,3 ---------------------------------------- table authors: ------------------------- author_id | name | email ------------------------- 1 | Sean | blah 2 | Sara | blah 3 | David | blah I want to pass everything in an array of 1 dimension (if possible) please assist! Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/ Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 In this case you want a third table 'article_authors' used to join the articles and authors together. eg; [pre] table articleauthors : ---------------------------- article_id | author_id ---------------------------- 0 | 1 0 | 2 1 | 1 1 | 2 1 | 3 ---------------- [/pre] Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078549 Share on other sites More sharing options...
saeed_violinist Posted June 29, 2010 Author Share Posted June 29, 2010 Thanks a lot! it seems to be more practical. can you provide a sample mysql select for this condition? Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078554 Share on other sites More sharing options...
trq Posted June 29, 2010 Share Posted June 29, 2010 To get the author names for the article 'test'. SELECT DISTINCT authors.name FROM article_authors, articles, authors WHERE article_authors.author_id = articles.id AND articles.title = 'test' Would return Sean and Sara. Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078572 Share on other sites More sharing options...
saeed_violinist Posted June 29, 2010 Author Share Posted June 29, 2010 To get the author names for the article 'test'. SELECT DISTINCT authors.name FROM article_authors, articles, authors WHERE article_authors.author_id = articles.id AND articles.title = 'test' Would return Sean and Sara. Thanks, but I tried this and it will return only 1 aouthor . or it is my bad, can you check it again please? Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078659 Share on other sites More sharing options...
kickstart Posted June 29, 2010 Share Posted June 29, 2010 Hi Think he has forgotten to link in the authors table SELECT DISTINCT c.name FROM articles a INNER JOIN article_authors b ON a.id = b.author_id INNER JOIN authors c ON b.author_id = c.id WHERE a.title = 'test' All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078665 Share on other sites More sharing options...
saeed_violinist Posted June 29, 2010 Author Share Posted June 29, 2010 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206134-multiple-authors-for-one-article/#findComment-1078708 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.