简体   繁体   English

使用 baguettebox 显示数据库中的图像

[英]display images from database with baguettebox

I'm trying to display images from my database with baguetteBox.js The problem is, baguetteBox works with <a> tags, but I display the images with <img> tags.我正在尝试使用 baguetteBox.js 显示我的数据库中的图像 问题是,baguetteBox 使用<a>标签,但我使用<img>标签显示图像。 I insert them in mediumblob to my database, and I don't have them in any folders.我将它们在 mediumblob 中插入到我的数据库中,但我没有在任何文件夹中。 So, here's the working baguetteBox:所以,这是工作的baguetteBox:

<div class="card-buttons">
<a href="1.jpg">
<div class="kepek">
<div class="btn-group mr-2" role="group" aria-label="Second group">
<button type="button" class="btn btn-primary">Képek</button>
</div>
</a>
<a href="2.jpg"></a>
</div>

and here's the working image listing:这是工作图像列表:

<?php
$sql = "SELECT id FROM cardimages ORDER BY id DESC"; 
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
?>
<img src="imageView.php?image_id=<?php echo $row["id"]; ?>" /><br/>
<?php       
}
mysqli_close($conn);
?>

but with this one, I can't see any image:但是有了这个,我看不到任何图像:

<div class="card-buttons">
<a href="1.jpg">
<div class="kepek">
<div class="btn-group mr-2" role="group" aria-label="Second group">
<button type="button" class="btn btn-primary">Képek</button>
</div>
</a>
<a href="2.jpg"></a>
<?php
$sql = "SELECT id FROM cardimages ORDER BY id DESC"; 
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result)) {
?>
<a href="imageView.php?image_id=<?php echo $row["id"]; ?>"></a>

<?php       
}
mysqli_close($conn);
?>
</div>

You need to use an <img> tag inside the <a> element that baguetteBox needs in order to trigger the lightbox.您需要在 baguetteBox 需要的<a>元素内使用<img>标签来触发灯箱。 A link element will never display an image See the second example on their homepage链接元素永远不会显示图像请参阅其主页上的第二个示例

So replace this line in your php file:所以在你的 php 文件中替换这一行:

<a href="imageView.php?image_id=<?php echo $row["id"]; ?>"></a>

with something like this (I'm assuming.. you might need to edit it some)像这样(我假设..你可能需要编辑一些)

<a href="imageView.php?image_id=<?php echo $row["id"]; ?>">
    <img src="imageView.php?image_id=<?php echo $row["id"]; ?>" />
</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM