下面代码的输出如下所示:
Current Discounts for: *category name*
<5 book cover images that link to books>
<5 book cover images that link to books>
MORE CURRENT DISCOUNTS image link
PAST Discounts for: *category name*
<5 book cover images that link to books>
<5 book cover images that link to books>
MORE PAST DISCOUNTS image link
问题:“我正在显示当前的折扣书籍和过去的折扣书籍(从 $Bookarray 和 $Bookoldarray 递增。当用户点击更多过去的折扣时,我希望当前的折扣消失,而过去的折扣是页面上唯一可见的部分。你如何在 PHP 中做到这一点?在 Visual Basic 中,如果按下 MORE CURRENT DISCOUNTS,我会创建一个增量变量并增加它,然后说如果 incvariable > 1 运行两个部分,否则只运行第二个部分。
这是代码
<p>Current Discounts for: <?php echo $whatcategory ?></p>
<?php
$currentp = isset($_GET['currentp']) ? $_GET['currentp'] : 1;
for($i = 0; $i < $currentp; $i++)
next($Bookarray);
if(current($Bookarray) === false){
reset($Bookarray);
$i = 0;
}
$currentIndex = current($Bookarray);
?>
<?=current($Bookarray)?></br><img src="images/bookdiv.jpg" width="547" height="20" /></br>
<a href="?currentp=<?=$i+1?>"><img src="images/current.jpg" width="215" height="32" /></a></br>
<p>Old Discounts for: ><?php echo $whatcategory ?></p>
<?php
$oldp = isset($_GET['oldp']) ? $_GET['oldp'] : 1;
for($i = 0; $i < $oldp; $i++)
next($Bookoldarray);
if(current($Bookoldarray) === false){
reset($Bookoldarray);
$i = 0;
}
$currentIndex = current($Bookoldarray);
?>
<?=current($Bookoldarray)?></br><img src="images/bookdiv.jpg" width="547" height="20" /></br>
<a href="?oldp=<?=$i+1?>"><img src="images/old.jpg" width="190" height="32" /></a>