Php 无图像显示时显示默认图像

Php 无图像显示时显示默认图像,php,Php,我在显示默认图像时遇到问题。我不知道确切的位置 $result=$conn->query(“SELECT*FROM adoption;”); 如果($result->num_rows!=NULL){ 而($rows=$result->fetch_assoc()){ $AAnimalName=$rows['AAnimalName']; $Abreed=$rows['Abreed']; $Asex=$rows['Asex']; $Acolor=$rows['Acolor']; $image=$row

我在显示默认图像时遇到问题。我不知道确切的位置

$result=$conn->query(“SELECT*FROM adoption;”);
如果($result->num_rows!=NULL){
而($rows=$result->fetch_assoc()){
$AAnimalName=$rows['AAnimalName'];
$Abreed=$rows['Abreed'];
$Asex=$rows['Asex'];
$Acolor=$rows['Acolor'];
$image=$rows['image'];
?>

按如下方式更改行:

<?php echo '<img onerror="this.src=\'img/logo.png\'" src = "admin/function/upload/'.$image.'" width = "248" height="190" class="age1" title>'?>

img/logo.png
将是默认图像

尝试以下操作:

If(file_exist('your_file_path'))
{
    echo '<img src = "admin/function/upload/'.$image.'" width = "248" height="190" class="age1" title>';
}
else
{
    echo '<img src = "admin/function/upload/default_image.jpg'" width = "248" height="190" class="age1" title>';
}
If(文件存在(“您的文件路径”))
{
回声';
}
其他的
{
回声';
}

这将检查文件是否存在。如果存在,它将显示给定的文件。否则将显示默认文件。

中尝试此操作,而
循环:

$image_location = "admin/function/upload/".$image;
if(file_exists($image_location )) {
    echo '<img src = "'.$image_location .'" width = "248" height="190" class="age1" title>';
}
else {
    echo '<img src = "admin/function/upload/default_image.jpg'" width = "248" height="190" class="age1" title>';
}
$image\u location=“admin/function/upload/”$image;
如果(文件存在($image\u位置)){
回声';
}
否则{
回声';
}

使用三元运算符并设置图像

<?php

  $image = (!empty($rows ['image'])) ? $rows ['image'] : "default.png" ;
 $image_location = "admin/function/upload/".$image;
echo '<img src = "admin/function/upload/'.$image.'" width = "248" height="190"    class="age1" title>';

   ?>


inside while loop?inside while loop?在
完成后。谢谢!!对你的代码进行了一些更正。谢谢你!file\u exist应该是file\u exist我想问更多。关于我的jquery工具提示。我想给你看一些东西。查看我的代码并尝试应用:
$(“.age1”).hover(function(){var imgScr=$(this.attr('src'));var html='';html+='';html+='图像标题';html+='';$(此).工具提示({content:html,track:true});});
好的,让我来看看try@Powerballs,请确保默认路径存在!请在您的答案中包含一个解释,以便将来的读者了解它是如何工作的?
<?php

  $image = (!empty($rows ['image'])) ? $rows ['image'] : "default.png" ;
 $image_location = "admin/function/upload/".$image;
echo '<img src = "admin/function/upload/'.$image.'" width = "248" height="190"    class="age1" title>';

   ?>