2013-05-31 53 views
0

我有2個php文件從mysql數據庫中檢索BLOB圖像。我的數據庫存儲了一些不同的圖像,因爲我嘗試在瀏覽器上顯示它們,只有第一個圖像顯示多次,例如:數據庫表存儲了5個圖像,瀏覽器將顯示第一個圖像5倍。 這裏是我的主要PHP文件的一個片段:只顯示數據庫的第一個條目

$strSQL = "SELECT * FROM images"; 
$rs = mysql_query($strSQL) or die (mysql_error()); 
echo "<table>"; 
while($row = mysql_fetch_array($rs)) { 

echo "<tr><td>"; 
echo " <img src=load_pic.php?id=".$row["id"]." id='img' width='100' height='100'></a>"; 
echo "</td></tr>"; 
} 

echo "</table>" 

和PHP文件,獲取圖像「load_pic.php」

$q="select * from images"; 
    $rec=mysql_fetch_array(mysql_query($q)); 
    $data=$rec['image']; 
    header('Content-Length: '.strlen($data)); 
    header("Content-type: image/".$rec['type']); 
    echo $data; 
+0

您給所有圖像使用相同的id ='img''。 ID必須是唯一的。我不確定爲什麼這會導致您看到的行爲,但無論如何您都需要修復它。 – Barmar

+0

@Barmar id ='img'只是我使用的所有圖像的標識符,其樣式 – Felix

+0

ID必須是唯一的。使用班級造型。 – Barmar

回答

2

load_pic.php腳本不使用id參數。它應該是:

$q = "select * from images where id = " . mysql_real_escape_string($_GET['id']); 
+0

+1 ..好趕上! –

+0

非常感謝你:) – Felix

相關問題