我对php和mysql很陌生。我正在尝试将mysql数据库中的数据显示到引导卡“ Card”中。我希望页面根据数据库中的条目数水平然后垂直显示多张卡片。现在,它只是垂直堆叠卡片。我想念什么?
<?php
$sql = "SELECT title, body, embed, image FROM test";
$resultset = mysqli_query($dbpatrol, $sql) or die("database error:". mysqli_error($dbpatrol));
while( $record = mysqli_fetch_assoc($resultset) ) {
?>
<body>
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<div>
<img class="card-img-top" src="photos/<?php echo $record['image']; ?>" alt="Card image cap">
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $record['title']; ?></h5>
<p class="card-text"><?php echo $record['embed']; ?></p>
<p class="card-text"><?php echo $record['body']; ?></p>
<div class="d-flex justify-content-between align-items-center">
<a href="domestic.php" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
<?php } ?>
答案 0 :(得分:0)
在循环之外尝试<body>
标签
<body>
<?php
$sql = "SELECT title, body, embed, image FROM test";
$resultset = mysqli_query($dbpatrol, $sql) or die("database error:". mysqli_error($dbpatrol));
while( $record = mysqli_fetch_assoc($resultset) ) {
?>
<div class="album py-5 bg-light">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="card mb-4 shadow-sm">
<div>
<img class="card-img-top" src="photos/<?php echo $record['image']; ?>" alt="Card image cap">
</div>
<div class="card-body">
<h5 class="card-title"><?php echo $record['title']; ?></h5>
<p class="card-text"><?php echo $record['embed']; ?></p>
<p class="card-text"><?php echo $record['body']; ?></p>
<div class="d-flex justify-content-between align-items-center">
<a href="domestic.php" class="btn btn-primary">Go somewhere</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
</body>