gpt4 book ai didi

PHP 在一行中输出所有表格

转载 作者:太空宇宙 更新时间:2023-11-04 04:12:13 24 4
gpt4 key购买 nike

该脚本应该获取文件夹中的所有图片,并将其中的前六张图片输出到表格中。然后我想添加一个小的下一个按钮,以便可以查看其余图像,但目前脚本只是将它们全部吐在一行中。所有这些,不仅仅是我想要的六个。除此之外,该代码还出现在网页底部,在文档中紧随其后的大量代码下方。

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 &#169; 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;
}

最佳答案

您没有关闭 <table> PHP 中的标记。这意味着 <p>我们要进入 table 。大多数浏览器不同意这种无效的 HTML,将非表格元素放在表格的前面,这就是表格下沉到底部的原因。

关闭</table>在您的 PHP 中,它应该可以正常工作。

为什么不试试这个:

<?php

$directory = 'images/gallery/';
$files1 = scandir($directory);
$x = 1;
echo"<table><tr>";
foreach ($files1 as $filename) {
if ($x <= 6) {
if ($x % 3==0) {
echo "</tr><tr>";
}
echo "<td><a data-lightbox='gallery' href='images/gallery/$filename'><img src='images/gallery/$filename'></a></td>";
$y = $x;
$x=$x+1;
} else {
break;
}
}
echo"</tr></table>";
?>

关于PHP 在一行中输出所有表格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20508783/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com