现在,它从MySQL数据库中提取数据并将数据(名称)放在两个并排的列中。我怎么做这个3?我没有PHP / HTML / CSS专家。为了数字标牌的目的,它应该从数据库中提取捐赠者的名字并显示它们。
$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>";
答案 0 :(得分:0)
点击此处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>";