2014-03-28 97 views
0

下面的代碼是我的PHP腳本的一部分,它應該在產品信息前顯示產品圖像。使用PHP插入圖像

每個圖像均標記爲product_id。那些自動增加並從MySQL數據庫接收的ID。

PHP代碼:

while($row=mysql_fetch_array($result)){ 
      $ProductName = $row['product_name']; 
      $ProductCat = $row['product_cat']; 
      $Email = $row['email']; 
      $ID = $row['product_id']; 
    //-display the result of the array 
      echo '<div ><img align="right" src="/project_images/$ID.JPG" width="280" height="125" /></div>'; 

的圖像顯示爲已損壞的瀏覽器。

是因爲圖像大小錯誤(可能太大)或代碼錯誤?

+1

當您直接從地址欄打開圖像的URL會發生什麼? –

+0

你可以檢查元素(布朗)和寫結果? – Anri

+0

是的,只是圖像損壞 –

回答

1

考慮與雙打替換單引號和逃避線內的雙引號,如下所示:

while($row = mysql_fetch_array($result)){ 
    $ProductName = $row['product_name']; 
    $ProductCat = $row['product_cat']; 
    $Email = $row['email']; 
    $ID = $row['product_id']; 
    // - display the result of the array 
    echo "<div ><img align=\"right\" src=\"/project_images/$ID.JPG\" width=\"280\" height=\"125\" /></div>"; 

PHP只是插入變量的內容轉換爲字符串,如果你把他們的雙引號字符串。在PHP單和雙引號的字符串之間的區別

更多信息可以在這裏找到:What is the difference between single-quoted and double-quoted strings in PHP?

+1

非常感謝你!現在它的工作正常 –

+0

@CashVai,請考慮也選擇答案,如果它幫助:) –