Copy link to clipboard
Copied
I have a database with three tables: books, authors and aux.
The books table stores the names of the books. The authors table stores the name of the authors. Table aux takes the id of the other two. I did this for the case of the same book has two or more authors
The query I did was the following:
SELECT authores.author, books.title
FROM aux, authors, books
WHERE aux.books_id = books.id AND aux.authors_id = authors.id
ORDER BY books.title ASC
How do I show the two authors for the same book?
For now, I'm using a simple table:
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>author</td>
<td>title</td>
</tr>
<?php do { ?>
<tr>
<td><?php echo $row_rsBooks['author']; ?></td>
<td><?php echo $row_rsBooks['title']; ?></td>
</tr>
<?php } while ($row_rsBooks = mysql_fetch_assoc($rsBooks)); ?>
</table>
Thus, the table presents two results for the same book, instead of uniting the two authors of the same book.
Copy link to clipboard
Copied
Book table has unique id for each entry. Author table has id for each book. JOIN your tables based on matching id to display author(s) for the book.
Copy link to clipboard
Copied
Thanks for the reply.
In the meantime, got what I wanted. The expression looks like this:
SELECT livros.titulo, GROUP_CONCAT(autores.autor SEPARATOR ',') AS Autores
FROM livros INNER JOIN aux ON aux.livros_id = livros.id INNER JOIN autores ON aux.autores_id = autores.id
GROUP BY livros.titulo
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more