【发布时间】:2013-12-11 01:23:41
【问题描述】:
脚本应该获取文件夹中的所有图片并将前六张图片输出到表格中。然后我想添加一个小的下一步按钮,这样人们就可以查看其余的图像,但目前脚本只是将它们全部吐在一行上。所有这些,不仅仅是我想要的六个。除此之外,代码也出现在网页底部,在文档中的许多代码下方。
PHP
<?php
$i = 0;
$directory = 'images/gallery/';
$files1 = scandir($directory);
$x = 0;
$y = 0;
$z = 0;
echo"<table><tr>";
foreach ($files1 as $filename) {
if ($z == $x + 6) {
break 2;
}
if ($x==1 || $x==0)
{
$x=$x+1;
}
else {
if ($y == $x + 3) {
echo "<td><a data-lightbox='gallery' href='images/gallery/$filename'><img src='images/gallery/$filename'></a></td></tr><tr>";
$y = $x;
$x=$x+1;
} else {
echo "<td><a data-lightbox='gallery' href='images/gallery/$filename'><img src='images/gallery/$filename'></a></td>";
$x = $x+1;
}
}
}
?>
HTML
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" >
<title>Perspective by Daniel Streich</title>
<link rel="stylesheet" type="text/css" href="scripts/css.css">
<link href="css/lightbox.css" rel="stylesheet">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/lightbox-2.6.min.js"></script>
<link href="css/lightbox.css" rel="stylesheet" >
</head>
<body>
<?php
$active = "Art";
include ('menu.php');
?>
<div class="wrapperRegular">
<p class="bigTitle">
Perspective by Daniel
</p>
<p class='actualText'>
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST TEST
</p>
<?php
include ('gallery.php');
?>
<br>
<div id="footer">
Copyright © Perspective by Daniel
</div>
</div>
</body>
CSS
#wrapperRegular {
margin: auto;
width: 50%;
}
p.bigTitle {
font-family: 'alluraregular';
font-size: 500%;
text-align: center;
color: 898888;
line-height: .33em;
}
p.actualText {
font-family: 'alluraregular';
color: 898888;
font-size: 1.5em;
}
table {
font-family: 'alluraregular';
color: 898888;
font-size: 1.5em;
margin: auto;
text-align: center;
border:5px;
}
【问题讨论】:
-
输出 html 是什么样的?
-
$z = 0和$x只会增加,因此您将永远无法通过$z == $x + 6联系到您的break。似乎是一个非常复杂的循环,只回显 2 行,每行 3。只需使用一个不断增加的计数器并检查模运算符。
标签: php html css html-table word-wrap