我正在尝试按特定字段(父级)对记录进行分组,并在手风琴中显示该父级记录的子级记录。我首先尝试使用GROUP BY
,但是只返回了一个子记录。另外,由于手风琴使用ID号,因此我必须为显示的每个手风琴增加ID。
我将SQL更改为ORDER BY
,而不是GROUP BY
,但现在显然没有将它们分组。
SELECT `edition`, `rep`, `rep_name`, `serial` FROM `vouchers` as `v`
INNER JOIN `reps` as `r` ON r.`rep_id` = v.`rep`
WHERE `sp_id` = :sp_id ORDER BY `edition`
我设法使手风琴ID位起作用,但不知道如何显示$value->edition (parent)
作为手风琴标题和$value->serial (child)
记录在手风琴中。
<div class="m-accordion m-accordion--bordered" id="m_accordion_2" role="tablist">
<?php
$i = 0;
foreach ($data['voucher_history'] as $history=>$value):
$i++;
?>
<div class="m-accordion__item">
<div class="m-accordion__item-head collapsed" role="tab" id="m_accordion_2_item_1_head" data-toggle="collapse" href="#m_accordion_2_item_<?php echo $i; ?>_body" aria-expanded=" false">
<span class="m-accordion__item-icon">
<i class="fa flaticon-user-ok"></i>
</span>
<span class="m-accordion__item-title">
<?php echo sanitize($value->edition) . ' - ' . $value->rep_name; ?>
</span>
<span class="m-accordion__item-mode"></span>
</div>
<div class="m-accordion__item-body collapse" id="m_accordion_2_item_<?php echo $i; ?>_body" class=" " role="tabpanel" aria-labelledby="m_accordion_2_item_2_head" data-parent="#m_accordion_2">
<div class="m-accordion__item-content">
<p>
<?php echo sanitize($value->serial); ?>
</p>
</div>
</div>
</div>
<?php endforeach; ?>
</div>