2017-08-24 107 views
0

晚上好專家:),我正在學習顯示圖像從數據庫使用PHP,我有問題。沒有錯誤信息,但圖像沒有顯示,請幫助。顯示從數據庫中的圖像,圖片不顯示使用php

這是我的代碼headline.php:

<?php 
 
include 'koneksi.php'; 
 

 
$tabel = 'isiberita'; 
 
$sql=$conn->query("SELECT * from $tabel order by tanggal desc limit 3"); 
 
    while ($tampil = $sql->fetch(PDO::FETCH_ASSOC)) { 
 
    echo "<p align='justify>'"; 
 
    echo "<img src='$tampil[gambar]' aligen='left'>"; 
 
    echo "<font valign='top'>"; 
 
    echo "<strong>"; 
 
    echo $tampil['judul']; 
 
    echo "</strong>"; 
 
    echo $tampil['tanggal']; 
 
    $data=substr($tampil['isi'],0,200); 
 
    echo $data; 
 
    echo "<a href='index.php?menu=detail_headline&id=$tampil[id_berita]'>&nbsp; baca lengkap>>>></a>"; 
 
    echo "</font></p><br>"; 
 
    } 
 

 
?>

這是我的圖片目錄: C:\ XAMPP \ htdocs中\ portalberita \甘巴爾

這是我的headline.php目錄: C:\ xampp \ htdocs \ portalberita

This my value database :

This output :

+0

更換

echo "<img src='$tampil[gambar]' aligen='left'>"; 

檢查輸出的實際HTML。什麼是'img'元素?這是你期望的嗎?當您的瀏覽器請求該映像時,服務器的響應是什麼? – David

回答

0

要從目錄中<img>標籤顯示的圖像,你必須指定圖像的路徑和名稱,如:

<img src="/images/imagename.ext"> <!-- If image folder exist on the same path where the code file exists --> 

<img src="../images/imagename.ext"> <!-- If image folder exist one level up where the code file exists --> 

所以請檢查image fol der和您的代碼目錄並相應地修復路徑。

0

嘗試

echo '<img src="' . $tampil['gambar'] . '" align="left" />';