我是 PHP 新手。所以我这里有几个问题:
所以,这是我的“item_choice”表:
╔══════════╦═════════╦═══════════════╗
║ c_id ║ item_id ║ choice_name ║
╠══════════╬═════════╬═══════════════╣
║ 1 ║ 100 ║ Set A ║
║ 2 ║ 100 ║ Set B ║
║ 3 ║ 100 ║ Set C ║
║ 4 ║ 100 ║ Set D ║
╚══════════╩═════════╩═══════════════╝
这是我的“item_subchoice”表:
╔══════════╦═════════╦═══════════════╦═══════════════╗
║ sc_id ║ c_id ║ option ║ price ║
╠══════════╬═════════╬═══════════════╬═══════════════╣
║ 1 ║ 1 ║ Fries ║ 4 ║
║ 2 ║ 1 ║ Coleslaw ║ 4 ║
║ 3 ║ 1 ║ Mac n Cheese ║ 5 ║
║ 4 ║ 2 ║ Fries ║ 4 ║
╚══════════╩═════════╩═══════════════╩═══════════════╝
到目前为止,这是我的结果(方形的东西是复选框):
Set A:
╔═╗
╚═╝ Fries,Coleslaw,Mac n Cheese 4,4,5
我想要实现的目标:
Set A:
╔═╗
╚═╝ Friese 4,
╔═╗
╚═╝ Coleslaw 4
╔═╗
╚═╝ Mac n Cheese 5
这是我当前的代码:
<div class="form-row">
<?php
if (isset($_GET['itemid'])) {
$choice_id = $_GET['itemid'];
$get_choice_id = "SELECT
t1.*,
GROUP_CONCAT(t2.sc_id) AS sc_ids,
GROUP_CONCAT(t2.option) AS choice_options,
GROUP_CONCAT(t2.price) AS choice_prices
FROM
item_choice t1
LEFT JOIN item_subchoice t2 ON t2.c_id = t1.c_id
GROUP BY t1.c_id";
}
}
?>
</div>
我也尝试过explode函数和array_merge,但我无法让它工作。提前致谢!
不负相思意