gpt4 book ai didi

php - 在每四个结果后打破一个 while 循环

转载 作者:太空宇宙 更新时间:2023-11-03 11:37:32 25 4
gpt4 key购买 nike

我正在尝试创建一个新行或打破我的结果行以下拉到我的结果集中的一个新行,因为此刻它们只是继续并突破容器并且不创建新的行,因为它到达容器的末端。

我的代码相当简单——我使用 bulma css 框架,特别是 is-3 类来显示每个结果,因此它在容器中提供了 4 列。因此,在每四个之后应该创建一个新行。

我的代码非常简单:

<div class="container">
<div class="columns projectList">
<?php while($stmt->fetch()) { ?>
<div class="column is-3">
<div class="card">
<div class="card-content">
<div class="content">
<p class="projectStatus">
<?php
if($phase == 0){
echo 'Phase: Pending';
}
elseif($phase == 1){
echo 'Phase: Planning';
}
elseif($phase == 2){
echo 'Phase: Design';
}
elseif($phase == 4){
echo 'Phase: Development';
}
else{
echo 'No Phase Added';
}
?>
</p>
<p class="projectTitle"><span>!</span><?php echo $projectName; ?></p>
<div class="projectTimes">
<div class="inner">
<span class="days">12</span>
<span class="for">Days Left In Design</span>
</div>
<div class="inner">
<span class="days">42</span>
<span class="for">Days to finish</span>
</div>
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item"><i class="material-icons">&#xE8EF;</i>32</a>
<a class="card-footer-item"><i class="material-icons">&#xE0B9;</i>10</a>
</footer>
</div>
</div>
<!-- END ROW HERE AND CREATE NEW ONE -->
<?php } $stmt->close(); } ?>
</div>
</div>

我的问题:如何在每四个结果后换行?

最佳答案

<div class="container">


<?php
$i = 0;
while($stmt->fetch()) {
if($i%4==0){
echo '<div class="columns projectList">';
}
$i++;
?>
<div class="column is-3">
<div class="card">
<div class="card-content">
<div class="content">
<p class="projectStatus">
<?php
if($phase == 0){
echo 'Phase: Pending';
}
elseif($phase == 1){
echo 'Phase: Planning';
}
elseif($phase == 2){
echo 'Phase: Design';
}
elseif($phase == 4){
echo 'Phase: Development';
}
else{
echo 'No Phase Added';
}
?>
</p>
<p class="projectTitle"><span>!</span><?php echo $projectName; ?></p>
<div class="projectTimes">
<div class="inner">
<span class="days">12</span>
<span class="for">Days Left In Design</span>
</div>
<div class="inner">
<span class="days">42</span>
<span class="for">Days to finish</span>
</div>
</div>
</div>
</div>
<footer class="card-footer">
<a class="card-footer-item"><i class="material-icons">&#xE8EF;</i>32</a>
<a class="card-footer-item"><i class="material-icons">&#xE0B9;</i>10</a>
</footer>
</div>
</div>
<?php
if($i%4==0){
echo '</div>'
$i = 0;
}
?>
<!-- END ROW HERE AND CREATE NEW ONE -->
<?php } $stmt->close(); } ?>

</div>
</div>

关于php - 在每四个结果后打破一个 while 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44562606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com