这是我的项目中的 while 循环:
<?php
$select = "SELECT * FROM nk_showcase";
$query = $db->rq($select);
while ($user = $db->fetch($query)) {
?>
<div class="index">
<a href="details.php?id=<?php echo $user['id']; ?>"><img width="200" height="171" alt="<?php echo $user['title']; ?>" src="<?php echo $url; ?>/images/niagakit/<?php echo $user['thumb']; ?>"/></a>
<h3><a href="<?php echo $url; ?>/"><?php echo $user['title']; ?></a></h3>
<p><a href="<?php echo $url; ?>/"><?php echo $user['url']; ?></a></p>
</div>
<?php } ?>
如您所知,这个 while 循环将为他们在我的数据库中找到的所有项目循环,所以我的问题是,如何限制此循环仅适用于我的数据库中的 10 个项目以及如何在每次刷新时轮换这些项目?
In SQL:
$select = "SELECT * FROM nk_showcase LIMIT 0,10";
或在 PHP 中:
$counter = 0;
$max = 10;
while (($user = $db->fetch($query)) and ($counter < $max))
{
... // HTML code here....
$counter++;
}
至于轮换,请参阅@Fayden的回答。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)