[英]How to display images using php when images in folder / DB
我的本地主機上有一個DB,其中的一個表包含屬於各種類別(image_category)的圖像。 圖像包含在一個文件夾中, ie: /gallery/xxxIMAGESxxx
我將hmtl
代碼保留在其中的php
文件高出一步的位置,以便在用戶屏幕上顯示。
現在我面臨的唯一問題是,當我想在網站上顯示圖像時,它們不會顯示。 取而代之的是,我僅獲得圖像的標題和說明,這些標題也來自數據庫。
在我的錨標簽的樣式部分中,我加入了
background-image: url(gallery/'.$row["imgFullNameGallery"].')">
圖片應顯示的位置。
我認為這與Base64
編碼有關,但是我無法指出應該在何處以及如何編碼/設置語法。 如果這是問題所在。
幫助將不勝感激。 提前謝謝。
//this is the php code with the call to the table with the images
<div class="display_CNC_Machining_images">
<?php
include_once 'includes/dbh.inc.php';
$sql = "SELECT * FROM gallery WHERE image_category = 'CNC_Machinery'";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt,$sql)) {
echo 'SQL statement failed!';
} else {
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
while ($row = mysqli_fetch_assoc($result)) {
//what's echoed out by the database
echo ' <a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$row["imgFullNameGallery"].')">
<div class="color-overlay">
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</div>
</a>';
}
}
?>
</div>
預期結果:
將顯示來自DB / localfolder的圖像以及來自DB的圖像標題和圖像描述。
實際結果:
僅顯示來自DB的圖像標題和圖像描述。
而不是這樣做:
echo '<a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$row["imgFullNameGallery"].')">
<div class="color-overlay">
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</div>
</a>';
做這個:
$image = $row["imgFullNameGallery"];
echo '<a class="images" style="background-repeat:no-repeat; background-image: url(gallery/'.$image.')">
<div class="color-overlay">
<h3>'.$row["titleGallery"].'</h3>
<p>'.$row["descGallery"].'</p>
</div>
</a>';
將$row["imgFullNameGallery"]
放入一個$row["imgFullNameGallery"]
的變量將防止沖突。
雙引號將與樣式中的引號沖突。
這應該顯示圖像。
還要檢查您的圖像是否存在於文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.