我有 3 个 MySQL 表:
shelf
---------------
id
project_id
label
books
---------------
id
project_id
label
booksOnShelves
---------------
id
shelf_id
book_id
project_id
user_id
我需要以表格格式显示书架上的书,例如:
History Fiction
------- --------
book 1 book 4
book 2 book 5
book 3
到目前为止,我只有这个:
SELECT
shelf.label,
books.label
FROM booksOnShelves
LEFT JOIN shelf ON (shelf.id = booksOnShelves.shelf_id)
LEFT JOIN books ON (books.id = booksOnShelves.book_id)
WHERE booksOnShelves.project_id = ".$_POST['pid']."
AND booksOnShelves.user_id = ".$_POST['uid']."
几件事......由于某种奇怪的原因,货架标签没有出现,但如果我删除查询中的所有其他部分,比如书籍标签,它就可以工作。另外,我只能在一长列中显示(通过循环)。我如何将它分成单独的列,或者如果在一列中,我如何每组书籍只显示一次货架标签?