我需要将图像保存到我的图库中并保存在数据库中

时间:2019-03-07 17:59:09

标签: php phpmyadmin

我需要我的画廊来显示保存在数据库中的图像。因此,与使用图像源标签不同,我需要用数据库中保存的内容填充画廊。因此,如果可以的话,从本质上向用户显示仅属于他们的所有图像?我猜画廊的html代码应该在while循环的php内?

html画廊代码:

 <div class="row">
        <div class="grid-full">
        <h3>ALL OF MY COMPETITION ENTRIES</h3>                  
            <div class="masonry">               
            <div class="item">
                <a href="Images/Nude.jpg" data-lightbox="gallery" data-title="Nude Pallette"><img alt src="Images/Nude.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/LakeDistrict.jpg" data-lightbox="gallery" data-title="The Lake District UK"><img alt src="Images/LakeDistrict.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/MarbleCase.jpg" data-lightbox="gallery" data-title="Mac Bliss"><img alt src="Images/MarbleCase.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/HeadwoodBeach.jpg" data-lightbox="gallery" data-title="Headwood Beach"><img alt src="Images/HeadwoodBeach.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/MacDesk.png" data-lightbox="gallery" data-title="Mac"><img alt src="Images/MacDesk.png" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/CoffeeonTable.jpg" data-lightbox="gallery" data-title="Fresh Latte"><img alt src="Images/CoffeeonTable.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/SilverMarble.jpg" data-lightbox="gallery" data-title="Mood Board"><img alt src="Images/SilverMarble.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Peonies.jpg" data-lightbox="gallery" data-title="Peonies"><img alt src="Images/Peonies.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Trousers.jpg" data-lightbox="gallery" data-title="Checked Trousers"><img alt src="Images/Trousers.jpg" class="ImgRound"></a>
            </div>  
            <div class="item">
                <a href="Images/Greys.jpg" data-lightbox="gallery" data-title="Greys Pallette"><img alt src="Images/Greys.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Sunset.jpg" data-lightbox="gallery" data-title="Places I would rather be..."><img alt src="Images/Sunset.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Grey2.jpg" data-lightbox="gallery" data-title="Simple Sweater"><img alt src="Images/Grey2.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Nature.jpg" data-lightbox="gallery" data-title="Sunrise"><img alt src="Images/Nature.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/autumn.jpg" data-lightbox="gallery" data-title="Autumn"><img alt src="Images/autumn.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Tulips.jpg" data-lightbox="gallery" data-title="White Tulips"><img alt src="Images/Tulips.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Pink.jpg" data-lightbox="gallery" data-title="Mood Board"><img alt src="Images/Pink.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/Outfit.jpg" data-lightbox="gallery" data-title="Outfit Ideas"><img alt src="Images/Outfit.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/BandW.jpg" data-lightbox="gallery" data-title="Simple"><img alt src="Images/BandW.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/TheLakeDistrict.jpg" data-lightbox="gallery" data-title="The Lake District"><img alt src="Images/TheLakeDistrict.jpg" class="ImgRound"></a>
            </div>
            <div class="item">
                <a href="Images/FlowerTable.jpg" data-lightbox="gallery" data-title="Dressing Table"><img alt src="Images/FlowerTable.jpg" class="ImgRound"></a>
            </div>
</div>
        </div>
    </div>

我的桌子:

Image Table

我认为我的PHP查询看起来像这样:

<?php

$query = "SELECT * FROM `tblImage` WHERE `fldMemberID` = 1";

$result = $conn -> query($query);

while($row = $result -> fetch_assoc()) {
?>

    <img src="<?php echo $row['fldFilePath'];  ?>"> <br>

<?php
}
$conn -> close();
?>

更新:运行代码后,出现以下错误,我应该在图库所在的位置出现: enter image description here

1 个答案:

答案 0 :(得分:2)

答案由另一个用户@RiggsFolly在评论中给出,进一步在我使用$conn -> close();的代码中删除了该代码后,代码运行正常。