在php中显示多次的列名字段?
我正在搜索数据库中的记录和显示的记录,但列名重复。请检查下面的图像在php中显示多次的列名字段?,php,Php,我正在搜索数据库中的记录和显示的记录,但列名重复。请检查下面的图像 <table border="1" align="center"> <thead> <tr> <th>User id</th> <th>First Name</th> <th>Last Name</th> &
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
</tbody>
</table>
<?php
}
} else {
echo "0 results";
}
用户id
名字
姓
将表代码放在循环之外,如下所示:-
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
<?php } } else { echo "0 results";}?>
</tbody>
</table>
用户id
名字
姓
将表代码放在循环之外,如下所示:-
<table border="1" align="center">
<thead>
<tr>
<th>User id</th>
<th>First Name</th>
<th>Last Name</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM newrecords_1 WHERE CONCAT( First_name, ' ',Last_name ) LIKE '%$name%' ORDER BY `First_name` ASC";
$result = $conn->query($query);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
<?php } } else { echo "0 results";}?>
</tbody>
</table>
用户id
名字
姓
每次抓取后都会得到头部分,因为在循环中也使用头部分。将收割台部件放在环上方,仅保留
下面是循环中的代码
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
每次抓取后都会得到头部分,因为循环中也使用头部分。将收割台部件放在环上方,仅保留
下面是循环中的代码
<tr>
<td><?php echo $row['ID'];?></td>
<td><?php echo $row['First_name'];?></td>
<td><?php echo $row['Last_name'];?></td>
</tr>
在开始循环之前创建标题。您正在为每个条目重新创建标题。感谢回复Martavis先生…就在循环重新创建时…@Hybreeder move tale code of loop在开始循环之前创建标题。您正在为每个条目重新创建标题。感谢您的回复,Martavis先生…就在loop重新创建时…@Hybreeder move tale code of loop先生。Anant先生,我尝试了您的代码,但只显示了一条记录,其余记录显示在一行中,而不是在一行中table@Hybreeder您没有正确使用代码。您的
仍在循环中。把它放在外面。再次检查我的代码绝对正确。。。现在工作很好…非常感谢你…工作now@Hybreeder很高兴为您提供帮助。:)阿南特先生,我尝试了您的代码,但只显示了一条记录,其余的记录显示在一行中,而不是在一行中table@Hybreeder您没有正确使用代码。您的
仍在循环中。把它放在外面。再次检查我的代码绝对正确。。。现在工作很好…非常感谢你…工作now@Hybreeder很高兴能帮助你。:)