使用php和mysql连续引导两张卡

xiozqbni  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(232)

我试图从数据库中获取数据,在前端,我使用bootstrap和php在一行两列的卡片中显示数据。但是,我得到了第一行的数据,但是剩下的是一张低于一的牌

<?php
    $con = mysqli_connect('localhost', 'root', '', 'applicants');
    if (!$con)
    {
        die('Could not connect: ' . mysql_error());
    }
    $qry = "select * from feedback";
    $result = mysqli_query($con, $qry);

?>
<div class="main-content">
            <div class="main-content-inner">
                <div class="row"> 
                    <div class="col-6 mt-5">
                        <?php $i=0;
                        while ($row = $result->fetch_assoc()) {
                            $i++;?>
                            <?php if ($i %2 == 0){?>
                    <!-- <div class="row"> --> 
                    </div>
                    <div class="col-6 mt-5"><?php } ?>
                        <div class="card">
                            <div class="card-body">
                                <h5 class="card-title"> <?php echo $row['username']?></h5>
                                <h6 class="card-subtitle mb-2 text-muted"><?php echo $row['email'] ?></h6>
                                <ul>
                                    <li>
                                        <div class="left alert alert-success" role="alert">
                                            <h6><?php echo $row['subject'] ?></h6>
                                            <p class="card-text"><?php echo $row['message'] ?></p>
                                        </div>
                                    </li>
                                </ul>                             
                            </div>
                        </div>
                        <?php if ($i %2 == 0){?>
                    </div>
                    <!-- </div> --><?php } ?>
                <!-- </div> -->
                </div>
                <?php } ?>
            </div>
        </div>
u5rb5r59

u5rb5r591#

你的行和列的标签好像掉了。请将它们与生成两行的代码进行比较:

<div class="main-content-inner">

            <div class="row"> 
              <div class="col-6 mt-5">
                <div class="card">
                  <div class="card-body">
                    <h5 class="card-title">Name</h5>
                    <h6 class="card-subtitle mb-2 text-muted">Email</h6>
                    <ul>
                      <li>
                        <div class="left alert alert-success" role="alert">
                          <h6>Subject</h6>
                          <p class="card-text">Message</p>
                        </div>
                      </li>
                    </ul>                             
                  </div>
                </div>
              </div>

              <div class="col-6 mt-5">
                <div class="card">
                  <div class="card-body">
                    <h5 class="card-title">Name</h5>
                    <h6 class="card-subtitle mb-2 text-muted">Email</h6>
                    <ul>
                      <li>
                        <div class="left alert alert-success" role="alert">
                          <h6>Subject</h6>
                          <p class="card-text">Message</p>
                        </div>
                      </li>
                    </ul>                            
                  </div>
                </div>
              </div>
            </div>

            <div class="row"> 
              <div class="col-6 mt-5">
                <div class="card">
                  <div class="card-body">
                    <h5 class="card-title">Name</h5>
                    <h6 class="card-subtitle mb-2 text-muted">Email</h6>
                    <ul>
                      <li>
                        <div class="left alert alert-success" role="alert">
                          <h6>Subject</h6>
                          <p class="card-text">Message</p>
                        </div>
                      </li>
                    </ul>                             
                  </div>
                </div>
              </div>

              <div class="col-6 mt-5">
                <div class="card">
                  <div class="card-body">
                    <h5 class="card-title">Name</h5>
                    <h6 class="card-subtitle mb-2 text-muted">Email</h6>
                    <ul>
                      <li>
                        <div class="left alert alert-success" role="alert">
                          <h6>Subject</h6>
                          <p class="card-text">Message</p>
                        </div>
                      </li>
                    </ul>                            
                  </div>
                </div>
              </div>
            </div>

</div>

相关问题