[英]I'm trying to print all columns in database to a horizontally table
I know I did something so stupid in my code but please help me .我知道我在我的代码中做了一些非常愚蠢的事情,但请帮助我。 As you see I'm trying to print all the information in database horizontally and when I run this, it only grabs client and doesn't grab the other columns from database.
正如你所看到的,我试图水平打印数据库中的所有信息,当我运行它时,它只抓取客户端而不抓取数据库中的其他列。 I hope all the information I gave you is enough.
我希望我给你的所有信息都足够了。
<table>
<?php $query = "SELECT * FROM 1d ORDER BY 'client' DESC";
$result = mysqli_query($conn, $query); ?>
<tbody>
<tr>
<th rowspan="6" style="color:black;font-size:30;width: 5%;height:400px;background-color:white;"><p style="width:100px;white-space: nowrap;position: relative;right:50%;white-space: nowrap; top: 57px;transform-origin: right;transform: rotate(-90deg);">1D : Preparation</p><br></th>
<th style="width:200px;">Client</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['client']; ?></td>
<?php } ?>
</tr>
<tr>
<th >Produit</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['produit']; ?></td>
<?php } ?>
</tr>
<tr>
<th >Equipe</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['equipe']; ?></td>
<?php } ?>
</tr>
<tr>
<th >Date</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['pdate']; ?></td>
<?php } ?>
</tr>
<tr>
<th >Description de Probleme</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['descdpro']; ?></td>
<?php } ?>
</tr>
<tr>
<th >Pilote</th>
<?php while($row = mysqli_fetch_assoc($result)){ ?>
<td ><?php echo $row['pilote']; ?></td>
<?php } ?>
</tr>
</tbody>
</table>
mysqli_fetch_assoc iterate throug the $result
variable one time. mysqli_fetch_assoc 遍历
$result
变量一次。 After the first cycle the others get false and you cannot see other elements than the first.在第一个循环之后,其他元素变为假,除了第一个之外,您看不到其他元素。
To avoid this you can populate an array with the results:为避免这种情况,您可以使用结果填充数组:
<?php
$query = "SELECT * FROM 1d ORDER BY 'client' DESC";
$result = mysqli_query($conn, $query);
$results = array();
while($row = mysqli_fetch_assoc($result)){
$results[] = $row;
}
?>
and change every cycle with this:并用这个改变每个周期:
<?php foreach($results as $row){ ?>
<td ><?php echo $row[ ... insert the key here ...]; ?></td>
<?php } ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.