![](/img/trans.png)
[英]First row of mysql data fetched through PHP is not displayed in the table
[英]the picture in the first row of the table displayed, while the rest of the pictures are not displayed PHP
我创建了一个包含猫信息的表。 在该猫信息中,我必须在表格中显示图片、名称、年龄、性别和描述。 问题是,只显示了表格第一行的图片,其余的都没有显示。 姓名、年龄、性别和描述在表格中显示数据时没有问题。 我必须在表格中显示 10 只猫的信息。 这是代码
<?php
include("include/connection.php");
$query = "SELECT * FROM cat";
$result = mysqli_query($conn, $query);
?>
<form action="add_cat.php"><div align="right"><button class="btn btn-success mb-2">Add New Cat</button></div></form>
<div class="table-wrapper-scroll-y my-custom-scrollbar">
<table class="table border border-dark" width="50%" cellpadding="5" cellspacing="5">
<thead class="thead-secondary">
<tr>
<th scope="col">Num</th>
<th scope="col">Cat ID</th>
<th scope="col">Picture</th>
<th scope="col">Name</th>
<th scope="col">Age</th>
<th scope="col">Gender</th>
<th scope="col">Description</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<!-- fetched data from cat table -->
<?php
$num =1;
while($row = mysqli_fetch_assoc($result)) { ?>
<tr>
<td><?php echo $num; ?></td>
<td><?php echo $row['id_cat']; ?></td>
<td><?php echo "<img src= '", $row['picture'] ,"' width='175' height='100' />" ?> </td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['age']; ?></td>
<td><?php echo $row['gender']; ?></td>
<td><?php echo $row['description']; ?></td>
<td>
<a href="edit_cat.php"><button class="btn btn-primary">Edit</button></a>
<a href="delete_cat.php?id_cat=<?php echo $row['id_cat']; ?>"><button class="btn btn-danger">Delete</button></a>
</td>
</tr>
<?php $num++;
} ?>
</tbody>
</table>
</div>
</form>
您的语法中有错字。 句点在 PHP 中连接字符串。 它应该是:
<?php echo "<img src= '". $row['picture'] ."' width='175' height='100' />" ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.