在底部更新我的源页面
在我的PHP foreach回声“打印”中,只有输出的第一行将所有打印值保存在一个水平行中,从第二个输出行开始,我不知道为什么它会分离为新的行。
我的前额代码:
foreach ($feedback as $item):
echo '<div class="card my-3 w-7">';
echo '<div class="card-body text-center">';
echo $item['custid'],str_repeat(' ', 3), $item['cakeid'], str_repeat(' ', 3),
"<form action='index.php' method='post'>
<input type='submit' name='cake_button' value='".$_SESSION['c'] = $item['cakename']."'>
</form>",
str_repeat(' ', 3), $item['ordertime'], str_repeat(' ', 3),
$item['pickuptime'], str_repeat(' ', 3), $item['pricepaid'];
echo '</div>';
echo '</div>';
endforeach;我的foreach在if语句函数中,请看这是整个代码块:
<?php if (!empty($_POST['body'])){
echo '<div class="card my-3 w-7">';
echo '<div class="card-body">';
echo str_repeat(' ', 75),"CustID", str_repeat(' ', 3),"CakeID", str_repeat(' ', 3),
"Cake Name", str_repeat(' ', 3), "Order Time", str_repeat(' ', 3),
"Pickup Time",str_repeat(' ', 3), "Price Paid";
echo '</div>';
echo '</div>';
foreach ($feedback as $item):
echo '<div class="card my-3 w-7">';
echo '<div class="card-body text-center">';
echo $item['custid'],str_repeat(' ', 3), $item['cakeid'], str_repeat(' ', 3),
"<form action='index.php' method='post'>
<input type='submit' name='cake_button' value='".$_SESSION['c'] = $item['cakename']."'>
</form>",
str_repeat(' ', 3), $item['ordertime'], str_repeat(' ', 3),
$item['pickuptime'], str_repeat(' ', 3), $item['pricepaid'];
echo '</div>';
echo '</div>';
endforeach;
}

这是我拍的截图,你可以看到,格式不一致。我希望每一行看起来都像第一行。我通过XAMPP从本地主机运行这个网站。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Leave Feedback</title>
</head>
<body>
<nav class="navbar navbar-expand-sm navbar-light bg-light mb-4">
<div class="container">
<a class="navbar-brand" href="#">Database draft</a>
</div>
</nav>
<main>
<div class="container d-flex flex-column align-items-center">
<img src="/db/feedback/img/logo.png" class="w-10 mb-3" >
<form method="POST" action="/db/feedback/index.php" class="mt-4 w-75">
<div class="mb-3">
<label for="body" class="form-label">Check Order for Cake Bakery</label>
<textarea class="form-control" id="body" name="body" placeholder="Enter your Customer ID"></textarea>
</div>
<div class="mb-3">
<input type="submit" name="submit" value="send" class="btn btn-dark w-100">
</div>
</div>
<form action="/db/feedback/index.php" method="POST"></form>
</form>
</main>
<footer class="text-center mt-5">
Updated: 2022/04/27
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
</body>
</html>发布于 2022-04-28 19:28:42
**您可以使用表格格式代替div类卡**
<?php if (!empty($_POST['body'])): ?>
<table class="table">
<thead>
<tr>
<th>CustID</th>
<th>CakeID</th>
<th>Cake Name</th>
<th>Order Time</th>
<th>Pickup Time</th>
<th>Price Paid</th>
</tr>
</thead>
<tbody>
<?php foreach($feedback as $item): ?>
<tr>
<td><?= $item['custid']; ?></td>
<td><?= $item['cakeid']; ?></td>
<td><form action='index.php' method='post'>
<input type='submit' name='cake_button' value="<?= $_SESSION['c'] = $item['cakename']; ?>">
</form></td>
<td><?= $item['ordertime']; ?></td>
<td><?= $item['pickuptime']; ?></td>
<td><?= $item['pricepaid']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>https://stackoverflow.com/questions/72049028
复制相似问题