Php photogallery未显示所选图片
编辑*我更新了一些代码,这些代码应该可以解决我的问题,但现在我在加载第2页时看不到任何img。我还在做错事 下面是它的样子 为了让我的php照片库正常工作,我苦苦挣扎了几个小时。这是学校的作业,所以我不允许使用任何JS 问题是我不知道如何做到这一点。第一页有6张太空船的照片。如果你点击其中一个shpips,你会进入第二个页面,并显示太空船。在宇宙飞船旁边有两个导航箭头,所以你可以选择来回图像 除了你们在第一页点击的血淋淋的飞船外,一切都正常,但并没有直接显示在第二页上 这是我有毛病的照片库 这是第一页Php photogallery未显示所选图片,php,session,echo,photo-gallery,Php,Session,Echo,Photo Gallery,编辑*我更新了一些代码,这些代码应该可以解决我的问题,但现在我在加载第2页时看不到任何img。我还在做错事 下面是它的样子 为了让我的php照片库正常工作,我苦苦挣扎了几个小时。这是学校的作业,所以我不允许使用任何JS 问题是我不知道如何做到这一点。第一页有6张太空船的照片。如果你点击其中一个shpips,你会进入第二个页面,并显示太空船。在宇宙飞船旁边有两个导航箭头,所以你可以选择来回图像 除了你们在第一页点击的血淋淋的飞船外,一切都正常,但并没有直接显示在第二页上 这是我有毛病的照片库 这
<?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>
助理秘书长
您忘记阅读第2页的参数“value”:
您应该在第二页的开头这样做:
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>
“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.
+1对于宁静号萤火虫级飞船的图片,你能粘贴剩下的代码吗?哦,糟糕,它仍然不起作用。现在我得到了正确的图片,但当页面加载时,它是一个空白。我在单击“过去”或“下一个箭头”时首先看到图片。我更新了我的帖子。你能更新你的帖子,看看你的代码现在是怎样的吗?是的,它已经更新了。我用新的(…值…?值=1…)更改了第一页中的HTML。然后我删除了第一页中设置“ship”的PHP代码。在第2页,我添加了新的if语句,以收集从第一页发送的帖子。然后,我将第二个if语句从0更改为1,并删除了第二个if语句PHP代码的一部分。好的,使用“==”比较器,而不是第二个页面中的“==”啊,就是这样做的!!谢谢你,伙计!我早上8点起床,感觉到我一直在这该死的画廊工作。
$_SESSION['ship'] = 1;// this makes second page start with the first image (and I want that pic to be //the one that is clicked.