2015-05-26 27 views
0

如果沒有任何特定圖像的圖像,我想顯示coming-soon.jpg圖像。我已經使用連接查詢從兩個表中獲取數據。所以在數據庫中有許多圖像用於不同的ID。但如果沒有任何圖像的特定身份證,那麼它的鞋coming-soon.jpg當數據庫中沒有任何圖像時的默認圖像

以下是我的代碼。

<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> 

回答

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

在while循環,這條線替換代碼。

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

我做出改變如下而不是沃金 – sachin

+0

做到這一點'的var_dump($行[ 「FILE_NAME」])',看看你做了什麼。 –

+0

我做了以下更改,但仍然不起作用 'while($ row = tep_db_fetch_array($ p-> recresult)) { $ file_id = $ row [「file_id」]; $ file_name =(!empty($ row [「file_name」])?$ row [「file_name」]:'default-img.jpg'); $ album_name = $ row [「album_name」];' – sachin

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