我有一个代码,从数据库中获取图像。如果没有找到图像,我需要告诉它显示另一个图像(它说没有可用的图像)。怎么做呢????
非常感谢您的建议
<a class="thumbimage" href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="images/thumb/<?php echo "$row[IMAGENAME]"; ?>.jpg" border="1" /></a>
试试这个:
<?php
$currentImage = "images/thumb/".$row[IMAGENAME].".jpg";
if(!file_exists($currentImage))
{
$currentImage = "PATH_TO_IMAGE_UNAVAILABLE";
}
?>
<a class="thumbimage" href="<?PHP mrd("$MyProductTitle", "$row[LID]", "$_GET[category]", "$rowxxx[MR]", "index.php?page=detail"); ?>"><img src="<?=$currentImage?>" border="1" /></a>
可以使用onerror属性。
用下面代码中的错误图像替换错误图像(3331913_origin .gif):
<img src="{some_error_src}" onerror="this.onerror=null;this.src='http://availableservicesllc.weebly.com/uploads/2/2/3/9/22390468/3331913_orig.gif'">
点击这里查看这个例子