如何让一个 PHP 页面有两个 "column" 区域?

How to make a PHP page have two "column" regions?

基本上我在做数字标牌,我试图将名字从 MySQL 数据库拉到 PHP 页面。现在它全部集中在一列中,但我希望结果并排在两列中。我怎样才能做到这一点?

$sql = "SELECT * FROM donor WHERE DonationAmount = 5000 AND Category = '1' or DonationAmount = 5000 AND Category IS NULL ORDER BY LastName ASC";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {

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

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

            }else{
                // Do stuff with the field
                    echo $row["DisplayName"]. "<br>";
            }

    }
} else {

}

基本上我希望这些数据分布在两列而不是一页上。

像这样输出字符串:

echo "<span style=\"width:50%;float:left;\">".$row['LastName']."</span>";

不要忘记从每个输出中删除 <br />

如果您的内容在 <div id="myDiv"> 中,请使用此 JS 函数并在内容加载后调用它

function splitValues() {
  var output = "";
  var names = document.getElementById('myDiv').innerHTML.split("<br>");
  for(var i in names) {
    output += "<span style=\"width:50%;float:left;display:inline-block;text-align:center;\">"+names[i]+"</span>";
  }
  document.getElementById('myDiv').innerHTML = output;
}

您可以使用 tables,并计算行数以确定是否需要开始一个新的 table 行。

$i = 0;
$total_rows = $result->num_rows;
echo "<table><tr>";
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>";
    }

}
echo "</tr></table>";