数据库中没有任何图像时的默认图像

时间:2015-05-26 09:42:04

标签: php mysql database image

如果没有该特定身份证的任何图像,我想显示即将到来的.jpg图像。我使用连接查询从两个表中获取数据。所以在数据库中有很多图像用于不同的id。但如果没有特定身份证的任何图像,那么它的鞋子即将来临。

下面是我的代码。

 <table width="100%" border="0" id="batch">
<? 
include("includes/paging.php");
$p = new post_pager(16); 
$photo_detail="select a.*,b.* from office_photo a,office_master b where a.album_id=b.album_id group by a.album_id";  
$p->query($photo_detail, "b.album_id asc", init());
$thispage = "Photo";
if ($p->page_total > 0 ) {  
$int_count = $p->get_counter();
$i=1;
while($row= tep_db_fetch_array($p->recresult))
{
$file_id=$row["file_id"];
$file_name=$row["file_name"];
$album_name=$row["album_name"];
$sqft=$row["sqft"];
$location=$row["location"];
$year=$row["year"];
$album_id=$row["album_id"];
if($i==1){ ?>
<tr>
<th>Project Name</th>
<th>Sq.Ft.</th>
<th>Loctaion</th>
<th>Year</th>
<th>Gallery</th>
</tr>
<? } ?>
<tr>
<td><a title="<?=$album_name;?>" href="office-photos.php?album_id=<?=$album_id?>" style="text-decoration:none">
<p style="text-align:center;padding-top:5px;width:140px;text-decoration:none"><?=$album_name;?></p></a></td>
<td><?=$sqft;?></td>
<td><?=$location;?></td>
<td><?=$year;?></td>
<td><a title="<?=$album_name;?>" href="office-photos.php?album_id=<?=$album_id?>" style="text-decoration:none">
<img src="upload/gallery_photo/thumb/<?=$file_name;?>"/></a></td>
</tr>
<? 
if($i==4){ 
$i=1; 
?>
<? }else {
$i = $i + 1;
}
}
}
?>
</table>

3 个答案:

答案 0 :(得分:1)

if(empty($file_name))
{$file_name="coming-soon.jpg";}//put any default image here

答案 1 :(得分:1)

在你的while循环中

,用这一行替换代码。

$file_name=(!empty($row["file_name"])?$row["file_name"] : 'default-img.jpg');

答案 2 :(得分:0)

if($file_name == '')
{
$file_name="defaultimg.jpg";//use your default image name here
}