我有两个表名book_list
和book_category
. 架构如下:
书单
+---------+--------+-----------+
| id_book | id_cat | book_name |
+---------+--------+-----------+
| 1 | 3 | Book Nam1 |
| 2 | 1 | Book Nam2 |
| 3 | 2 | Book Nam3 |
+---------+--------+-----------+
book_category
+--------+----------+-----------+-------+
| id_cat | cat_name | id_parent | level |
+--------+----------+-----------+-------+
| 1 | name1 | 0 | 1 |
| 2 | name1.1 | 1 | 2 |
| 3 |name1.1.1 | 2 | 3 |
+--------+----------+-----------+-------+
代码尝试:
SELECT a.id_book, a.id_cat, a.book_name, b.cat_name, b.level
FROM book_list a
INNER JOIN book_category b ON a.id_cat = b.id_cat
我需要操纵结果数组以添加面包屑,其中每个都有指向自身的链接,例如:
table row:
<td>3(id_book)</td>
<td>Book Nam3 (book_name)</td>
<td>
<a href="handle.php?id=<?=id_cat;?>">Name 1</a> »
<a href="handle.php?id=<?=id_cat;?>">Name 1.1</a> »
<a href="handle.php?id=<?=id_cat;?>">Name 1.1.1</a>
</td>
希望我表达了我的观点,并感谢您的帮助。