以下代码的输出如下:
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中,如果按下更多当前折扣,我会创建一个增量变量并递增它,然后说IF 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>
答案 0 :(得分:1)
当您重新加载页面并返回PHP以显示下一组折扣时,您可以在整个“当前折扣”部分放置一个php if
块并检查'oldp' '变量已经设定。
<?php
// Check if user clicked on Past Discounts
if(!isset($_GET['oldp']) {
?>
<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>
<?php
}
// End if (Hide current discounts if past discounts clicked)
?>
<p>Old Discounts for: ><?php echo $whatcategory ?></p>