0

I have these tree tables in the database:

books
book_id book_title
      1 PHP
      2 Lincoln

books_authors
book_id author_id
      1         1
      1         3
      2         1
      2         2

authors
author_id author_name
        1 Dan Brown
        2 Ernest Hemingway
        3 William Shakspare

I want to visualice the Book Name and the authors , and I do it with two join statements.

My question is how to visualice the table in a PHP page like that:

http://postimg.org/image/69kjbhjmd/

I mean if the books are the same to visualice their authors on the same line.

Strawberry
  • 33,750
  • 13
  • 40
  • 57
  • 1
    PHP by Dan Brown and the Bard. Now, that's a book I would read. – Strawberry Oct 08 '14 at 11:30
  • Just set up a simple loop in PHP. There are a million tutorials on this. – Strawberry Oct 08 '14 at 11:37
  • If you want to do it with just SQL, the following question might help you: http://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-microsoft-sql-server-2005. The key is to group by `books_id` but concatenate the values of all the columns that were ommited due to the grouping. Bit of a pain. – Jonathon Oct 08 '14 at 11:39
  • Easier solution would be like Strawberry said, do the query without a `group by` and use PHP to loop and print out. – Jonathon Oct 08 '14 at 11:43
  • How did you convert the images into text like that ? And how to do it with PHP ? – Anonymous User Oct 08 '14 at 11:48

1 Answers1

0

Try this, do some googling before posting question here. There are so many simple join available to learn

SELECT B.book_title,C.author_name
FROM books_authors A
JOIN books B ON A.book_id = B.book_id
JOIN authors C ON A.author_id = C.author_id
Shafeeque
  • 2,039
  • 2
  • 13
  • 28