douda5706 2014-04-06 17:53
浏览 28

PHP将循环拆分为3列以避免分页

I am using a PHP while loop to get review data from the database. However, when reviews are longer than 1 line is breaks the grid system (I am using Bootstrap 3) and then the page looks messy. I have thought about two solutions, a read more button and show a fixed height for all of the boxes. Alternatively, split the data received from the database into 3 columns so it will not break the page.

Preferably I would like to split the data from the loop so it shows the data in 3 columns. Image of the problem

This is the while loop that fetches the data:

        <?php 
      while($row = mysqli_fetch_array($result)) {
        $data = mysqli_fetch_array(mysqli_query($con, "SELECT first_name, last_name FROM transactions WHERE order_id = '{$row['order_id']}'"));
        $name = $data['first_name']. ' '. mb_substr($data['last_name'], 0, 1);
        if($row['rating'] == 5) $star = '<span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span>'; 
        if($row['rating'] == 4) $star = '<span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span>'; 
        if($row['rating'] == 3) $star = '<span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span>'; 
        if($row['rating'] == 2) $star = '<span class="glyphicon glyphicon-star review_star"></span><span class="glyphicon glyphicon-star review_star"></span>'; 
        if($row['rating'] == 1) $star = '<span class="glyphicon glyphicon-star review_star"></span>'; 
      ?>
      <div class="col-md-4">
        <div id="box_review">
          <h3><?php echo $star; ?></h3>
          <h5 class="thin"><?php echo $row['date'] ?></h5>
          <blockquote>
            <p><?php echo $row['comment'] ?></p>
            <footer><?php echo $name ?></footer>
          </blockquote>
        </div> 
      </div>
    <?php } ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 公交车和无人机协同运输
    • ¥15 stm32代码移植没反应
    • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
    • ¥100 连续两帧图像高速减法
    • ¥15 组策略中的计算机配置策略无法下发
    • ¥15 如何绘制动力学系统的相图
    • ¥15 对接wps接口实现获取元数据
    • ¥20 给自己本科IT专业毕业的妹m找个实习工作
    • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
    • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)