2014-03-28 100 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,请考虑也选择答案,如果它帮助:) –