我有一张包含20种不同计划的表格。
plans.sql
id | planName
1 | Alpha
2 | Omega
3 | Gamma
...
每个计划包含3个不同级别(青铜级,银级,金级)。我想在这样的页面上显示所有计划:
Alpha Alpha Alpha
Bronze Silver Gold
Omega Omega Omega
Bronze Silver Gold
...
到目前为止,我正在使用while循环从数据库中提取计划名称,如下所示:
$plansql = "select * from plans";
$resultps = $conn->query($plansql);
$resultp = array();
if (mysqli_num_rows($resultps) > 0) {
while($plan = mysqli_fetch_assoc($resultps)) {
$resultp[] = '<div class="col-lg-2">
<div class="panel price panel-red">
<div class="panel-heading text-center">
<h3>'.$plan['planName'].'</h3>
<h3>'.$planLevel.'</h3>
</div>
<div class="panel-body text-center">
<p class="lead panel-body-pricing" style=""><strong>'.$plan['planPrice'].'</strong></p>
</div>
<ul class="list-group list-group-flush text-center">
<li class="list-group-item"><i class="icon-ok text-danger"></i>
This plan is perfect for...
</li>
</ul>
<div class="panel-footer">
<a class="btn btn-lg btn-block btn-danger" href="#">SEE DETAILS</a>
</div>
</div>
</div>';
}
}
我在while循环之外显示结果
.join("",$resultp).
效果很好,但如何为每个计划添加不同的级别?
答案 0 :(得分:1)
如果要将其显示为html表,可以使用此
echo '<table>';
foreach ($resultp as $planName) {
echo "<tr>
<td>$planName<br>Bronze</td>
<td>$planName<br>Silver</td>
<td>$planName<br>Gold</td>
</tr>";
}
echo '</table>';