简单的php for循环,在添加循环之前工作正常,但我想要它打印4行3个产品。问题是它将所有12个项目放入一行!然后它会在页面底部再创建3个空行。
添加了代码的更新版本,认为它可能对其他人有所帮助,虽然它显示正确但我必须从表中提取15条记录。
<?php for($i = 0; $i < 4; $i++) { ?>
<div class="row products">
<?php while($product = mysqli_fetch_assoc($featured)) : ?>
<!-- product-->
<div class="col-md-4 col-sm-6">
<div class="product">
<div class="image">
<a href="#"><img src=" <?= "images/wheels/wheelphotos/". $product["bigpic"]; ?>" alt= "<?= $product["manufacturer"]; ?>" class="img-responsive"></a>
<div class="quick-view-button"><button type="button" onclick="quickModal(<?= $product["recid"]; ?>)" class="btn btn-default btn-sm">Quick view</button></div>
</div>
<div class="text">
<p class="brand"><a href="#"><?= $product["manufacturer"]; ?></a></p>
<h3> <a href="detail.html"><?= $product["diam"]; ?></a></h3>
<p class="price">$<?= $product["rrp"]; ?></p>
<button class="btn btn-default btn-sm btn-primary">Details</button>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php } ?>
<?php for($i = 0; $i < 4; $i++) { ?>
<div class="row products">
<?php
$j = 0;
while($product = mysqli_fetch_assoc($featured)) :
$j++;
if($j > 3 ){
break;
}
?>
<!-- product-->
<div class="col-md-4 col-sm-6">
<div class="product">
<div class="image">
<a href="#"><img src=" <?= "images/wheels/wheelphotos/". $product["bigpic"]; ?>" alt= "<?= $product["manufacturer"]; ?>" class="img-responsive"></a>
<div class="quick-view-button"><button type="button" onclick="quickModal(<?= $product["recid"]; ?>)" class="btn btn-default btn-sm">Quick view</button></div>
</div>
<div class="text">
<p class="brand"><a href="#"><?= $product["manufacturer"]; ?></a></p>
<h3> <a href="detail.php"><?= $product["diam"]; ?></a></h3>
<p class="price">$<?= $product["rrp"]; ?></p>
<button class="btn btn-default btn-sm btn-primary" href="detail.php">Details</button>
</div>
</div>
</div>
<?php endwhile; ?>
</div>
<?php } ?>
答案 0 :(得分:1)
您的JPanel graphicsPanel = new JPanel();
int incorrectGuesses =0;
@Override
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2D = (Graphics2D) g;
BasicStroke aStroke = new BasicStroke(15.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
g2D.setStroke(aStroke);
g2D.setColor(Color.BLUE);
switch (incorrectGuesses) {
case 10:
g2D.drawLine(200, 200, 150, 250); // Left leg
case 9:
g2D.drawLine(200, 200, 250, 250); // Right leg
case 8:
g2D.drawLine(150, 150, 200, 175); // Left arm
case 7:
g2D.drawLine(250, 150, 200, 175); // Right arm
case 6:
g2D.drawLine(200, 200, 200, 150); // Torso
case 5:
g2D.drawOval(175, 100, 50, 50); // Head
case 4:
g2D.drawLine(200, 100, 200, 50);// Noose
case 3:
g2D.drawLine(200, 50, 100, 50);//Plank
case 2:
g2D.drawLine(100, 300, 100, 50); //Post
case 1:
g2D.drawLine(20, 300, 300, 300); //Stage
}
repaint();
graphicsPanel.add(new HangmanGraphics());
}
循环将运行与您选择的查询一样多的记录。如果你需要在一定数量的记录之后退出该循环,你可以使用一个变量来计算你完成循环的次数,然后{while}循环中的while
。您的break
循环将完成下一次迭代并打印“row”div,for
循环将处理下一对记录,直到您再次while
。