Jump to content

Multiple authors for one article


saeed_violinist

Recommended Posts

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!

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.