我试过这段代码。但只有一个x按钮,它只删除我想要的第一个值 粗体的值有x按钮。我该怎么办? 。该 图片显示在示例下方。谢谢你提前,
if ($specializations = selected_specializations()) {
$groupped_spec = [];
$groupped_pcon = [];
foreach ($specializations as $specialization) {
$spec = $specialization["Specialization"];
$groupped_pcon[$spec][] = $specialization["PossibleCondition"];
$groupped_spec[$spec][] = array_only($specialization, ['id', 'Specialization', 'Specialization1', 'Specialization2']);
}
foreach ($groupped_spec as $Specialization => $groupped_specializations) {
$PossibleCondition = implode("<br />", array_unique($groupped_pcon[$Specialization]));
echo " <b>{$PossibleCondition}</b><br />\n";
foreach (array_unique_arrays($groupped_specializations, ['id']) as $specialization) {
$id = $specialization["id"];
$spec = $specialization["Specialization"];
$spec1 = $specialization["Specialization1"];
$spec2 = $specialization["Specialization2"];
?>
<button class="btn btn-link" name="delete_spec" aria-label="Left Align" data-id="<?php print $id;?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
<ul>
<a href="hgapp.php?doc=<?php echo $spec ?>"><u><?php echo $spec ?></u></a>
<a href="hgapp.php?doc=<?php echo $spec1 ?>"><u><?php echo $spec1 ?></u></a>
<a href="hgapp.php?doc=<?php echo $spec2 ?>"><u><?php echo $spec2 ?></u></a>
</ul>
<?php
}
?>
<?php
}
}
?>
</div>
<script type="template" id="specialization_group_template">
<b>{PossibleCondition}</b><br />{specializations}<br />
</script>
<script type="template" id="specialization_template">
<button name="delete_spec"class="btn btn-link" aria-label="Left Align" data-id="{id}">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
<ul>
<a href="hgapp.php?doc={Specialization}"><u>{Specialization}</u></a>
<a href="hgapp.php?doc={Specialization1}"><u>{Specialization1}</u></a><br>
<a href="hgapp.php?doc={Specialization2}"><u>{Specialization2}</u></a>
</ul>
</script>
答案 0 :(得分:-1)
您有一个结果,在该结果中,您列出了3个规格,并且您只放了一个按钮。
检查代码的这一部分我为每个规格添加了按钮,因为您需要按规格按钮。你需要自己定义其余部分。就像按钮将如何执行删除等等。您需要传递哪些数据才能执行此操作。等。
foreach (array_unique_arrays($groupped_specializations, ['id']) as $specialization) {
$id = $specialization["id"];
$spec = $specialization["Specialization"];
$spec1 = $specialization["Specialization1"];
$spec2 = $specialization["Specialization2"];
?>
<ul>
<a href="hgapp.php?doc=<?php echo $spec ?>"><u><?php echo $spec ?>
</u></a>
<button class="btn btn-link" name="delete_spec" aria-label="Left Align" data-id="<?php print $id;?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
<a href="hgapp.php?doc=<?php echo $spec1 ?>"><u><?php echo $spec1 ?>
</u></a>
<button class="btn btn-link" name="delete_spec" aria-label="Left Align" data-id="<?php print $id;?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
<a href="hgapp.php?doc=<?php echo $spec2 ?>"><u><?php echo $spec2 ?>
</u></a>
<button class="btn btn-link" name="delete_spec" aria-label="Left Align" data-id="<?php print $id;?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
</ul>
<?php
}