im试图从mysqli中获取数据并将其显示在表上。可以找到表标题的所有内容,如果有5个数据,它将对每个数据重复标题5次。
有人知道我在哪里做错了吗?我怀疑我的php代码上的if循环。 下面是代码。
PHP代码:
TextBox.Size = New Windows.Size(Math.Max(InsideRadius, 20)
表输出:
答案 0 :(得分:-1)
当您说“我怀疑我的php代码上的if循环”时,您是正确的。只需将表标题,主体的开头和主体的结尾移出循环,仅将表行留在...
// Moved this from inside the loop
<table class="table">
<thead class=" text-primary">
<th>
Name
</th>
<th>
Age
</th>
<th>
Gender
</th>
<th>
Passport Number
</th>
<th>
Nationality
</th>
<th>
Citizen
</th>
<th>
Address
</th>
<th>
Caught Place
</th>
<th>
Current Status
</th>
<th>
Based At
</th>
<th>
Phone Number
</th>
<th>
Family Phone Number
</th>
<th>
Company Phone Number
</th>
</thead>
<div class="table-responsive">
<?php
//get rows query
$query = $db->query("SELECT * FROM register");
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
?>
<tbody>
<tr>
<td>
<?php echo $row["Name"]; ?>
</td>
<td>
<?php echo $row["Age"]; ?>
</td>
<td>
<?php echo $row["Gender"]; ?>
</td>
<td>
<?php echo $row["PassportNumber"]; ?>
</td>
<td>
<?php echo $row["Nationality"]; ?>
</td>
<td>
<?php echo $row["Citizen"]; ?>
</td>
<td>
<?php echo $row["Address"]; ?>
</td>
<td>
<?php echo $row["CaughtPlace"]; ?>
</td>
<td>
<?php echo $row["CurrentStatus"]; ?>
</td>
<td>
<?php echo $row["BasedAt"]; ?>
</td>
<td>
<?php echo $row["PhoneNumber"]; ?>
</td>
<td>
<?php echo $row["FamilyPhoneNumber"]; ?>
</td>
<td>
<?php echo $row["CompanyPhoneNumber"]; ?>
</td>
</tr>
</tbody>
</table>
<tbody>
<?php } }else{ ?>
<p>Data(s) not found</p>
<?php } ?>
// Moved this from inside the loop
</tbody>
</table>
</div>