dqpdb82600 2016-06-28 15:03
浏览 10
已采纳

如何使这个PHP / HTML页面有3列而不是2列?

Right now, it pulls data from a MySQL database and puts the data (names) in two side-by-side columns. How do I make this 3? I'm no PHP/HTML/CSS expert. It's just supposed to pull the names of the donors from the database and display them, for digital signage purposes.

$sql = "SELECT * FROM donor WHERE DonationAmount = 1000 AND Category = '2' ORDER BY LastName ASC";
$result = mysqli_query($conn, $sql);
$i = 0;
$total_rows = $result->num_rows;
echo "<table><tr>";
if (mysqli_num_rows($result) > 0) {
    echo "<p style=font-size:20px;>In Honor Of</p>";
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {

        // test if the DisplayName field is empty or not
    echo "<td>";
    if(empty($row['DisplayName']))
    {
            // it's empty!
            if(empty($row['FirstName'])){
                    echo $row['LastName'];
            }

            else{
                    echo $row["LastName"]. ", " . $row["FirstName"];
            }

    }else{
            // Do stuff with the field
            echo $row["DisplayName"]. "";
    }
    echo "</td>";
    $i++;
    if($i % 2 == 0 && $i != $total_rows) {
            echo "</tr><tr>";
    }

  }
} else {

}
echo "</tr></table>";
  • 写回答

1条回答 默认 最新

  • duanhao7786 2016-06-28 15:21
    关注

    Check here MOD

    $column = 3;
    $sql = "SELECT * FROM donor WHERE DonationAmount = 1000 AND Category = '2' ORDER BY LastName ASC";
    $result = mysqli_query($conn, $sql);
    $i = 0;
    $total_rows = $result->num_rows;
    
    echo "<h2>In Honor Of</h2>";
    
    echo "<table><tr>";
    if ($total_rows > 0) {
        // output data of each row
        while($row = mysqli_fetch_assoc($result)) {
    
            // test if the DisplayName field is empty or not
        echo "<td>";
        if(empty($row['DisplayName']))
        {
                // it's empty!
                if(empty($row['FirstName'])){
                        echo $row['LastName'];
                }
    
                else{
                        echo $row["LastName"]. ", " . $row["FirstName"];
                }
    
        }else{
                // Do stuff with the field
                echo $row["DisplayName"]. "";
        }
        echo "</td>";
        $i++;
    
        /*i % column */
        if($i % $column == 0 && $i != $total_rows) {
                echo "</tr><tr>";
        }
    
      }
    } else {
    
    }
    echo "</tr></table>";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动