0

EDIT* I have updated with some codes that should solve my problem, but now I cant see any img when page 2 loads. I am still doing something wrong.

Here is how it looks like

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

I am struggeling for hours to get my php photogallery to work. It is an assignment for school so I am not allowed to use any JS at all.

The problem is that I dont know how to achive this. On page one there is 6 picture of space ships. If you click on one of the shpips you come to the second page, and that space ship is displayed. Beside the spaceships is two arrows for navigation so you can chose back and forth image.

Everything working except that bloody ship you click on on first page does not get displayed direct on second page!

Here is my photogallery with fault. http://lavis.se/ass_6/labb_del2_2.php

Here is the first page

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

And second page

<?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>
user2586036
  • 41
  • 1
  • 1
  • 8

1 Answers1

0

You are forgetting to read the parameter "value" of the 2nd page:

You should do something like that at the beginning of your second page:

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

Also, your html for the images in the first page should be:

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

And the session asignation on the second page should be corrected like that:

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

"1" instead of "0"

or better:

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

And last, the following line on your code in page 1, is not useful, so you can delete it:

$_SESSION['ship'] = 1;// this makes second page start with the first image (and I want that pic to be //the one that is clicked.
ElLocoCocoLoco
  • 387
  • 3
  • 11
  • oh crap it is still not working. Now I get the right picture, but when page load it is an empty space. I see the pic first when I click past or next arrow. I update my post. – user2586036 Jul 25 '13 at 15:14
  • Could you update your post to see exactly how your code is now? – ElLocoCocoLoco Jul 25 '13 at 15:25
  • yes it is updated. I changed the HTML in page one with new (..values..?value=1..). Then I removed the PHP code in page one which set the 'ship'. On page 2 I added the new if statment to scoop up the post who is sent from page one. Then I changed the second if statment from 0 to 1, and removed part of second if statment PHP code. – user2586036 Jul 25 '13 at 15:39
  • ok, use the "==" comparator instead of "===" in your second page – ElLocoCocoLoco Jul 25 '13 at 15:40
  • AAAH THAT DID IT!! Thanks a lot mate! I got up at 08:00 this morning and sence that I have been working with this bloody gallery. – user2586036 Jul 25 '13 at 15:43
  • your are welcome, please dont forget to change the question as answered. – ElLocoCocoLoco Jul 25 '13 at 15:45
  • hmm not sure how you do that. – user2586036 Jul 25 '13 at 15:51
  • how I did it? are you kidding? I spent time analysing your code and answering to your question in detail. I you need more details, here there are: You will passing a paramater in your firt page to the second page (where the client did a clic) using a querystring variable, but you werent using it in your second page. So the second pae didn't know where the click was done. Also the "===" in php is used to exact compare (with types)(implicitly converted to int when you compared). the "===" operator was returning false, you were comparing an "int" with an "string" (values of _GET are strings). – ElLocoCocoLoco Jul 26 '13 at 07:53
  • aha sorry mate was a misunderstanding. I did not find the green check to the left in order to finish the question. You where perfectly clear on your answer, and it worked like a charm. – user2586036 Jul 26 '13 at 14:08