【发布时间】:2016-01-29 19:26:46
【问题描述】:
我有一张表格,里面有我所有的发票项目作为包裹:
Table: invoice_items
invoice_item_id | package_id | addon_1 | addon_2 | addon_3 | ...
----------------|------------|---------|---------|
1 | 6 | 2 | 5 | 3 |
然后是我的另一张桌子:
Table: addons
addon_id | addon_name | addon_desc |
----------|--------------|--------------------------|
1 | Dance Lights | Brighten up the party... |
2 | Fog Machine | Add some fog for an e... |
我不想占用空间将插件名称存储在我的 invoice_items 表中,我只想将 addon_id 包含在 addon_1、addon_2 等列中。
在查询 invoice_item 行时如何获取插件的名称?
现在我只是将它编程到页面中,如果 addon_id == 1,则回显“Dance Lights”等,但我想在查询中执行此操作。这是我当前的查询:
$invoice_items_SQL = "
SELECT invoice_items.*, packages.*
FROM `invoice_items`
INNER JOIN packages ON invoice_items.invoice_item_id = packages.package_id
WHERE `event_id` = \"$event_id\"
";
所以我可以用包做到这一点,但这只是因为每行只有一个 package_id,但最多有 9 个插件:(
【问题讨论】: