编辑* 我已经更新了一些可以解决我的问题的代码,但是现在我在第 2 页加载时看不到任何 img。我仍然做错了什么。
这是它的样子
http://i664.photobucket.com/albums/vv8/Lapplander890/stackHelp2_zpseb38de6e.jpg
我挣扎了几个小时才能让我的 php photogallery 正常工作。这是学校的作业,所以我根本不允许使用任何 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>