dtu1747 2018-05-20 17:17
浏览 26
已采纳

循环通过以青铜开头的关卡

I have a table with 20 different plans.

plans.sql

id | planName
1  | Alpha
2  | Omega
3  | Gamma
...

Each plan contains 3 different levels (Bronze, Silver, Gold). I want to display all the plans on a page like this:

Alpha   Alpha  Alpha
Bronze  Silver Gold

Omega  Omega  Omega
Bronze Silver Gold
...

So far I'm pulling the plan names from the database with a while loop as follow:

$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>';
}
}

I display the result outside the while loop

.join("",$resultp).

It works great, but how do I add the different levels to each plan?

  • 写回答

1条回答 默认 最新

  • dth42345 2018-05-20 17:38
    关注

    If you want to display it as an html table, you could use this

    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>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装