이미지 없을 때 대신 다른 이미지 뜨게 하려면 어떻게 하나요
본문
<?php for ($i=0; $i<2; $i++) { ?>
<?php
$sql_file="SELECT * FROM g5_board_file where bo_table='{$bo_table}' and wr_id={$list[$i]['wr_id']}";
echo "<li style ='display:table-cell;width:145px;padding:0 24px;'>";
$result_file = sql_query($sql_file);
$row_file=sql_fetch_array($result_file);
//echo "<ul class='roll_img'>";
echo "<a href=\"".$list[$i]['href']."\" style='display:inline-block;overflow:hidden;'>";
echo "<img onerror='this.src='noimg.gif';' src='{$g5['path']}/data/file/{$bo_table}/$row_file[bf_file]' style='width:100%;' />"; // 이미지 출력
echo "</a>";
echo "<a style='margin-top:5px;display:block' href=\"".$list[$i]['href']."\">";
echo $list[$i]['subject'];
echo "</a>";
echo "</li>";
//echo "</ul>";
?>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<span style="text-align:center;display:block;width:90%;margin:0 auto;">게시물이 없습니다.</span>
<style type="text/css">
.latest_board img {display:none;}
</style>
<?php } ?>
이미지가 없을 때 대신 뜨게 해야하는데
<img error='src='/images/..''
이렇게 해도 안됩니다.
!-->
답변 2
'this.src='noimg.gif';'
=>'this.src=\"noimg.gif\"'
이 부분은 그누보드의 기본 갤러리 스킨의 list.skin.php 파일의 87번줄 정도에
if($thumb['src']) {
$img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'">';
} else {
$img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
}
부분을 참고하시면 좋을 듯 합니다.
썸네일 이미지가 없을때 span태그로 가로, 세로 크기를 정하고 그 안쪽에 no Image라는 글자를 보여주고 있습니다.
여기에 적용된 스타일시트는
.gall_href span {display:inline-block;background:#f7f7f7;text-align:center;line-height:10em}
이것 이구요.