0

下面代码的输出如下所示:

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>
4

1 回答 1

1

当您重新加载页面并返回 PHP 以显示下一组折扣时,您可以if在整个“当前折扣”部分周围放置一个 php 块并检查是否已设置“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>
于 2013-10-23T17:32:34.700 回答