循环PHP数字进行幻灯片放映

时间:2014-03-09 20:46:00

标签: php

我的网页看起来有点像这样。

 <div class="ecigcontainer">
 <div class="backbutt"><?php include("php/back.php"); ?></div>
 <div class="ecig"><?php include("php/ecig.php"); ?></div>
 <div class="forwardbutt"><?php include("php/forward.php"); ?></div>
 </div>

一个像这样工作的后退按钮。

<?php
if (isset($_GET["ecig"])) {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>

前进按钮几乎有相同的代码,显示器看起来像这样。

<div class="ecigpic">
<img src="images/ecigs/<?php include("php/ecigcounter.php"); ?>.png" height="400px" />
</div>
<div class="ecigdesc">
<?php
if (isset($_GET["ecig"])) {
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
} else {
$_GET["ecig"] = 1;
include("ecigs/" . $_GET["ecig"] . ".php");
echo "<h3>" . $ecigname . "</h3>";
echo "<p>" . $ecigdesc . "</p>";
}?>
</div>

用“ecigcounter”来做到这一点。

<?php
if (isset($_GET["ecig"])) {
echo $_GET["ecig"];
} else {
$_GET["ecig"] = 1;
echo $_GET["ecig"];
}?>

但这个问题的全部原因是,如何制作它所以它只显示数字1-40?有点丢失,似乎无法弄明白,把它放在需要去的地方。

1 个答案:

答案 0 :(得分:0)

所需要的只是

<?php
if (isset($_GET["ecig"])) {
if ($_GET["ecig"] == 1){
    $back = 40;
    echo "<a href=\"?ecig=" . $back . "\">";
    echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}
} else {
$back = $_GET["ecig"] - 1;
echo "<a href=\"?ecig=" . $back . "\">";
echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";
}?>

这个小小的剧本创造了世界。

if ($_GET["ecig"] == 1){
    $back = 40;
    echo "<a href=\"?ecig=" . $back . "\">";
    echo "<img src=\"images/ecigs/" . $back . ".png\" height=\"300px\" /></a>";