Q:

photo gallery php echo pic on submit

I got an assignment to build a photo gallery that works without JS, and you have a working navigation where you can go to next or previous photo.
I did a counter that counted from 1-6 (number of pics) then I made if statsment. That is if $spaceship = 1,2,3,4,5,6 echo "that img".
It did not work. When I put on the echo my counter failed to count and ALL img display same time after refresh!! god damn.
First part of code is sessions
<?php

//$start = $_GET['value'];

//echo $start;

//$test = hej;
//echo $test;
session_start(); 
$_SESSION['ship'] = ((isset($_SESSION['ship'])) ? 
$_SESSION['ship'] : 0); 
if(isset($_GET['add'])){ 
     $_SESSION['ship']++; 

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

}
?>

And here is the code so I cycle through the 6 numbers
<?php
if ($_SESSION['ship']  > 6)
{
    $_SESSION['ship']  = 1; 
}
if ($_SESSION['ship']  < 1)
{
    $_SESSION['ship']  = 6; 
}
echo $_SESSION['ship'] 
?>

And here is my failure, where I tried to attach each number to diffrent pics and echo them out.
if ( $_SESSION['ship']  = 1 ) {
           echo "<img src=\"img/space/battlestar.jpg\"/>";  }
if ( $_SESSION['ship']  = 2 ) {
           echo "<img src=\"img/space/enterprise.jpg\"/>";  }
if ( $_SESSION['ship']  = 3 ) {
           echo "<img src=\"img/space/integrity.jpg\"/>";   }
if ( $_SESSION['ship']  = 4 ) {
           echo "<img src=\"img/space/millenium.jpg\"/>";   }
if ( $_SESSION['ship']  = 5 ) {
           echo "<img src=\"img/space/planetes.jpg\"/>";    }
if ( $_SESSION['ship']  = 6 ) {
           echo "<img src=\"img/space/serenity.jpg\"/>";    }

A:

instead of checking equality your if statements are setting the value of ship.
so to fix it use this:
if ( $_SESSION['ship']  === 1 ) {
           echo "<img src=\"img/space/battlestar.jpg\"/>";  }
if ( $_SESSION['ship']  === 2 ) {
           echo "<img src=\"img/space/enterprise.jpg\"/>";  }
if ( $_SESSION['ship']  === 3 ) {
           echo "<img src=\"img/space/integrity.jpg\"/>";   }
if ( $_SESSION['ship']  === 4 ) {
           echo "<img src=\"img/space/millenium.jpg\"/>";   }
if ( $_SESSION['ship']  === 5 ) {
           echo "<img src=\"img/space/planetes.jpg\"/>";    }
if ( $_SESSION['ship']  === 6 ) {
           echo "<img src=\"img/space/serenity.jpg\"/>";    }

edit: be better to use elseif as well so instead use:
if ( $_SESSION['ship']  === 1 ) {
           echo "<img src=\"img/space/battlestar.jpg\"/>";  }
elseif ( $_SESSION['ship']  === 2 ) {
           echo "<img src=\"img/space/enterprise.jpg\"/>";  }
elseif ( $_SESSION['ship']  === 3 ) {
           echo "<img src=\"img/space/integrity.jpg\"/>";   }
elseif ( $_SESSION['ship']  === 4 ) {
           echo "<img src=\"img/space/millenium.jpg\"/>";   }
elseif ( $_SESSION['ship']  === 5 ) {
           echo "<img src=\"img/space/planetes.jpg\"/>";    }
elseif ( $_SESSION['ship']  === 6 ) {
           echo "<img src=\"img/space/serenity.jpg\"/>";    }

HTH;
Nick
(ps. go Firefly!)

