Php 使用表格和while循环在“大图像”下显示较小的图像
我会尽量简化(不会让上传图片)。 这是我的密码。我希望第一个图像显示为大图像,较小的图像在下面一个接一个地显示。我将附加css和php。 现在图像是这样显示的:大,小,大,小,大…等等 PHPPhp 使用表格和while循环在“大图像”下显示较小的图像,php,html,css,mysqli,Php,Html,Css,Mysqli,我会尽量简化(不会让上传图片)。 这是我的密码。我希望第一个图像显示为大图像,较小的图像在下面一个接一个地显示。我将附加css和php。 现在图像是这样显示的:大,小,大,小,大…等等 PHP // Get image $sqlimg= "SELECT * FROM images where Horse_ID='$hid'"; $resultimg = $conn->query($sqlimg); // $rowimg = $res
// Get image
$sqlimg= "SELECT * FROM images where Horse_ID='$hid'";
$resultimg = $conn->query($sqlimg);
// $rowimg = $resultimg->fetch_assoc();
$a = 1;
// Start table
echo "<table id='horses'>";
while($rowimg = mysqli_fetch_assoc($resultimg)){
if($a <= 1){ //number of cells in row
// Big Image
?>
<tr>
<td id="big">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</td></tr><tr>
<?php
$a++;
}
else {
// second row
?>
<tr>
<td id="small">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</td></tr>
<?php
$a = 1;
}
}
echo "</table>";
每次输出小图像时,您都将$a重置为1。这将导致输出的下一个图像变大。您可能只想在每次输出图像时增加$a。去掉$a=1而不是else块,并将$a++移出if/else块
// Get image
$sqlimg= "SELECT * FROM images where Horse_ID='$hid'";
$resultimg = $conn->query($sqlimg);
$a = 1;
// Start table
echo "<table id='horses'>";
while($rowimg = mysqli_fetch_assoc($resultimg)){
if($a <= 1){ //number of cells in row
// Big Image
?>
<tr>
<td id="big">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</a>
</td>
</tr>
<?php
}
else {
// second row
?>
<tr>
<td id="small">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</a>
</td>
</tr>
<?php
}
$a++;
}
echo "</table>";
//获取图像
$sqlimg=“从图像中选择*,其中Horse_ID='$hid';
$resultimg=$conn->query($sqlimg);
$a=1;
//起始表
回声“;
而($rowimg=mysqli_fetch_assoc($resultimg)){
如果($a)
谢谢,但小图像只是输出到大图像:(我设法做了一个更改,下面的图像很小,但它们也创建了一个新的TR标记。因此,我将它们放在了底部大图像的右侧。我所做的只是删除了第二个a=1,没有移动a++听起来像是将$a++移到了while循环之外,而不是在if/else块之外。很高兴你这么做了它不起作用。:)我的意思是我把小图像弄得很小,但它们不在正确的位置。第一个小图像很好,但第一个图像和其他图像之间有很大的差距。我不确定你想要什么。如果空间太大,那么你的表格单元格上可能有一些填充物?
// Get image
$sqlimg= "SELECT * FROM images where Horse_ID='$hid'";
$resultimg = $conn->query($sqlimg);
$a = 1;
// Start table
echo "<table id='horses'>";
while($rowimg = mysqli_fetch_assoc($resultimg)){
if($a <= 1){ //number of cells in row
// Big Image
?>
<tr>
<td id="big">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</a>
</td>
</tr>
<?php
}
else {
// second row
?>
<tr>
<td id="small">
<a href="uploads/<?php echo $rowimg['imageName'];?>" data-lightbox="image-1">
<img src="uploads/<?php echo $rowimg['imageName'];?> " />
</a>
</td>
</tr>
<?php
}
$a++;
}
echo "</table>";