0
我必須從MySQL表格中顯示MySQL表格中的數據。 我已經得到了代碼,它將顯示MySQL表格中7行中的第一行,但它重複行9次,而不是顯示所有7行。 我做錯了什麼?在html表格中顯示mysql數據PHP
<?php
require 'database.php';
//get all product data
$query = 'SELECT * FROM products';
$products = $db->query($query);
$products = $products->fetch();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>SportsPro</title>
</head>
<body>
<form id="Header" name="Header" method="post">
<?php include 'header.php'; ?>
</form>
<form id="Content" name="Content" method="post">
<table width="500" border="1">
<tr>
<th scope="col">Code</th>
<th scope="col">Name</th>
<th scope="col">Version</th>
<th scope="col">Release Date</th>
<th scope="col"> </th>
</tr>
<?php foreach ($products as $product) { ?>
<tr>
<td><?php echo $products['productCode']; ?></td>
<td><?php echo $products['name']; ?></td>
<td><?php echo $products['version']; ?></td>
<td><?php echo $products['releaseDate']; ?></td>
<td><input type = "submit" value = "Delete" align = "right" ></td>
</tr>
<?php } ?>
</table>
<p><a href="add_product.php">Add Product</a></p>
</form>
<form id="Footer" name="Footer" method="post">
<?php include 'footer.php'; ?>
</form>
</body>
</html>
檢查的var_dump($產品)'結果;' – goseo