Php照片库没有显示所选图片

时间:2013-07-25 12:06:41

标签: php session echo photo-gallery

编辑*我已经更新了一些应该解决我的问题的代码,但是现在当第2页加载时我看不到任何img。我还在做错事。

以下是它的样子

http://i664.photobucket.com/albums/vv8/Lapplander890/stackHelp2_zpseb38de6e.jpg

我花了好几个小时让我的php照片库工作。这是学校的任务,所以我根本不允许使用任何JS。

问题是我不知道如何实现这个目标。在第一页有6张太空船图片。如果单击其中一个,则转到第二页,并显示该太空飞船。在太空飞船旁边有两个用于导航的箭头,因此您可以选择前后图像。

除了您在第一页上点击的血腥船外,其他所有工作都不会直接显示在第二页上!

这是我的故事照相馆。 http://lavis.se/ass_6/labb_del2_2.php

这是第一页

<?php
session_start(); 
//$_SESSION['ship'] = 1;
/*
$_SESSION['ship'] = ((isset($_SESSION['ship'])) ? 
$_SESSION['ship'] : 0); 


if(isset($_GET['add'])){ 
     $_SESSION['ship']++; 

}
if(isset($_GET['sub'])){ 
     $_SESSION['ship']--; 

}

*/
?>

<!DOCTYPE html>


<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>ass6</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

        <link rel="stylesheet_del2" href="css/normalize.css">
        <link rel="stylesheet" href="main_del2.css">
        <script src="js/vendor/modernizr-2.6.2.min.js"></script>
        <script src="main_del2.min.js"></script>
         <script src="jquery-1.2.6.pack.js.js"></script>
    </head>
    <body>

        <div id="imgwrap">
                <h1>Spaceships</h1>

                    <a href="basicForm2.php?value=1"><img src="img/space/planetes_thumb.jpg" alt="serenity"/></a>
                    <a href="basicForm2.php?value=2"><img src="img/space/serenity_thumb.jpg" alt="serenity"/></a>
                    <a href="basicForm2.php?value=3"><img src="img/space/battlestar_thumb.jpg" alt="battlestar"/></a>
                    <a href="basicForm2.php?value=4"><img src="img/space/enterprise_thumb.jpg" alt="enterprise"/></a>
                    <a href="basicForm2.php?value=5"><img src="img/space/millenium_thumb.jpg" alt="millenium"/></a>
                    <a href="basicForm2.php?value=6"><img src="img/space/integrity_thumb.jpg" alt="integrity"/></a>


        </div>
   <body>   



    </body>
</html>
>

第二页

<?php
session_start(); 
if(isset($_GET['value'])){ 
     $_SESSION['ship'] = $_GET['value'];
}
if(!isset($_SESSION['ship']))
      $_SESSION['ship'] = 1;


if(isset($_GET['add'])){ 
     $_SESSION['ship']++; 

}
if(isset($_GET['sub'])){ 
     $_SESSION['ship']--; 

}

?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>ass6</title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->

       <link rel="stylesheet" href="main_del2.css" type="text/css"/>

    </head>

<body>  



</form> 
<?php
if ($_SESSION['ship']  > 6)
{
    $_SESSION['ship']  = 1; 
}
if ($_SESSION['ship']  < 1)
{
    $_SESSION['ship']  = 6; 
}
echo $_SESSION['ship'] 
?>
<a href="labb_del2_2.php"><h2> Spaceships </h2></a>
        <div id="imgcontainer">
            <form action="basicForm2.php" method="get"> 
<input type="submit" name="add" value="add" id="right"/> 
</form> 

<!--
<img src="fileDir2.php" alt="Image created by a PHP script" width="100" height="80">
-->
<form action="basicForm2.php" method="get"> 
<input type="submit"  name="sub" value="sub" id="left"/> 
                <?php


if ( $_SESSION['ship']  === 1 ) {
        echo "<img src=\"img/space/planetes.jpg\"/>";   }
    if ( $_SESSION['ship']  === 2 ) {
        echo "<img src=\"img/space/serenity.jpg\"/>";   }   
      if ( $_SESSION['ship']  === 3 ) {
        echo "<img src=\"img/space/battlestar.jpg\"/>"; }

if ( $_SESSION['ship']  === 4 ) {
    echo "<img src=\"img/space/enterprise.jpg\"/>"; }   
     if ( $_SESSION['ship']  === 5 ) {
            echo "<img src=\"img/space/millenium.jpg\"/>";  }
if ( $_SESSION['ship']  === 6 ) {
             echo "<img src=\"img/space/integrity.jpg\"/>"; }   
        ?>


        </div>

</html>

1 个答案:

答案 0 :(得分:0)

您忘记阅读第2页的参数“值”:

你应该在第二页开头做类似的事情:

if(isset($_GET['value'])){ 
     $_SESSION['ship'] = $_GET['value'];
}

此外,第一页中图片的html应为:

 <a href="basicForm2.php?value=1"><img src="img/space/serenity_thumb.jpg" alt="serenity"/></a>
 <a href="basicForm2.php?value=2"><img src="img/space/battlestar_thumb.jpg" alt="battlestar"/></a>
 <a href="basicForm2.php?value=3"><img src="img/space/enterprise_thumb.jpg" alt="enterprise"/></a>
 <a href="basicForm2.php?value=4"><img src="img/space/millenium_thumb.jpg" alt="millenium"/></a>
 <a href="basicForm2.php?value=5"><img src="img/space/integrity_thumb.jpg" alt="integrity"/></a>
 <a href="basicForm2.php?value=6"><img src="img/space/planetes_thumb.jpg" alt="planets"/></a>

第二页上的会话请求应该像这样纠正:

$_SESSION['ship'] = ((isset($_SESSION['ship'])) ? 
$_SESSION['ship'] : 1);    

“1”而不是“0”

或更好:

 if(!isset($_SESSION['ship']))
      $_SESSION['ship'] = 1;

最后,第1页代码中的以下行没有用,所以你可以删除它:

$_SESSION['ship'] = 1;// this makes second page start with the first image (and I want that pic to be //the one that is clicked.