gpt4 book ai didi

php - mysql php 的异常表输出

转载 作者:行者123 更新时间:2023-11-29 18:48:18 26 4
gpt4 key购买 nike

为什么我会在表输出中得到这些额外的层?我需要从 table 上删除那些额外的层。我做错了什么?这里究竟发生了什么?更新了代码。

<?php
$con=mysqli_connect("localhost","root", "", "cop");

if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql= mysqli_query ($con, "SELECT FirstName, Practice FROM Members");

echo "
<style>th {
font: bold 11px 'Trebuchet MS', Verdana, Arial, Helvetica,
sans-serif;
color: #6D929B;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(images/bg_header.jpg) no-repeat;
}

th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}</style>


<table border='1'>
<tr>
<th>FirstName</th>
<th>Practice</th>
</tr>";

while($row = mysqli_fetch_array($sql))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['Practice'] . "</td>";
echo "</tr>";
}

echo "</table>";

Unusual Table output

最佳答案

如果您要做这样的事情,您将能够判断数据中是否存在空列值

while( $row = mysqli_fetch_array($sql) ){

if( !empty( $row['FirstName'] ) && !empty( $row['Practice'] ) ){
$firstname=$row['FirstName'];
$practice=$row['Practice'];
} else{
$firstname=$practice='empty';
}

echo "
<tr>
<td>{$firstname}</td>
<td>{$practice}</td>
</tr>";

}

或者,如果已知该行包含值而不是空单元格,则仅输出该行

while( $row = mysqli_fetch_array($sql) ){

if( !empty( $row['FirstName'] ) && !empty( $row['Practice'] ) ){
$firstname=$row['FirstName'];
$practice=$row['Practice'];
echo "
<tr>
<td>{$firstname}</td>
<td>{$practice}</td>
</tr>";
}
}

关于php - mysql php 的异常表输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44481406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com