목록에서 이미지가 없을때 랜덤 이미지를 출력하고 싶습니다

목록에서 이미지가 없을때 랜덤 이미지를 출력하고 싶습니다

QA

목록에서 이미지가 없을때 랜덤 이미지를 출력하고 싶습니다

본문

현재 사용중인 웹진형 스킨의 list.skin.php의 내용입니다.

(작은별 님의 스킨입니다. http://gnustudy.com/bbs/board.php?bo_table=gnu_pds&wr_id=12 에서 no_image.zip 파일)

기본은 이미지가 없을때 지정된 noimage.gif가 나오도록 되어 있습니다.

이걸 수정해서 noimage.gif 대신 랜덤하게 이미지가 나오게 하려고 합니다.

 

 

 


  <td class="td_subject">
                <div class="sb_vimg">
                    <?if($is_member){?> <a href="<?php echo $list[$i]['href'] ?>"> <?}?>
                    <?php
                    if (!$list[$i]['is_notice']) {
                        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
                        
            if($thumb['src']) {
                            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
 
                        } else { 
                          $img_content = '<img src="'.$board_skin_url.'/img/noimage.gif" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
 
                        }
                        echo $img_content;
                    } 
                     $wr_content= cut_str(strip_tags($list[$i]['wr_content']), 175); //글자수 자르기
                    ?>
                    </a> 
                </div>

 

 

검색을 해서, 랜덤 이미지 관련 글을 찾아보았습니다. 그래서...

 

스킨 디렉토리의 img 디렉토리 밑에 noimage_random 이라는 디렉토리는 만들고

그안에 00여개의 jpg 파일 (01.jpg~ 90.jpg)를 넣은 상태에서.....

 

 

 

 


(기존)    $img_content = '<img src="'.$board_skin_url.'/img/noimage.gif" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
 
(수정)
 <?
     for($i=1;$i<=99;$i++) {
        $image[$i] = $i.".jpg"}
 
      $random = time()%count($image);
  ?>
 
 
  $img_content = '<img src="'.$board_skin_url.'/img/noimage_random/.echo $image[$random]" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';

 

 

...짜집기로 라고 고쳐봤는데....

 

Parse error:syntax error, unexpected '<' in ~어쩌고저쩌고 에러가 나오고 있습니다

 

syntax error 인걸 보니, 기초적인 부분인거 같아서... \" 를 여기저기 넣어봤는데도 해결을 못하고 있습니다

 

(syntax error가 해결된다고 해도, 제대로 작동될런지도 잘 모르겠습니다만 ㅜ_ㅜ)

 

 

 

(p.s.) sysntax errors는 <?  와 ?> 를 중복으로 넣어서 그런거였네요 ㅡ_ㅡ;;;;

742ba5f9f432398757bb13a3ac999e73_1473000193_3365.jpg
 

그런데,  sysntax errors를 해결하니까, 위와 같이 화면이 나옵니다.

원래는 게시물이 10개 이상 있는데, 저렇게 이미지가 깨지고 내용도 나오지 않으면서 1줄 밖에 나오지 않고 있습니다.

 

 

 

어떻게 수정을 해야, 이미지가 없을 경우에는  지정된 디렉토리 안의 이미지 파일을 읽어서 목록에 랜덤하게 출력할 수 있을까요?

 

 

이 질문에 댓글 쓰기 :

답변 1

$img_content = '<img src="'.$board_skin_url.'/img/noimage_random/' . sprintf('%02d', rand(1, 90))  . '.jpg' . '" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">'; 

계속 질문이 수정되는 바람에..... 현재 최종 상태입니다.




 <td class="td_subject">
                <div class="sb_vimg">
                    <?if($is_member){?> <a href="<?php echo $list[$i]['href'] ?>"> <?}?>
                    <?php
                    if (!$list[$i]['is_notice']) {
                        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
                        
            if($thumb['src']) {
                            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
                        } else {
                            for($i=1;$i<=99;$i++) {
                               $image[$i] = $i.".jpg"}
                           $random = time()%count($image);

                         $img_content = '<img src="'.$board_skin_url.'/img/noimage_random/' . sprintf('%02d', rand(1, 90))  . '.jpg' . '" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">'; 
                        }
                        echo $img_content;
                    }
                     $wr_content= cut_str(strip_tags($list[$i]['wr_content']), 175); //글자수 자르기
                    ?>
                    </a>
                </div>


......Parse error: syntax error, unexpected '}' in /어쩌고~/list.skin.php on line 116 에러가 나서,

116줄에 해당하는...  $image[$i] = $i.".jpg"} 에서 } 를 제거 했더니...


......Parse error: syntax error, unexpected '$random' (T_VARIABLE) in /어쩌고/list.skin.php on line 117

117줄에 해당하는  $random = time()%count($image); 에서 에러가 나오는 상태입니다. ㅠㅠ



(p.s) 116줄에 해당하는 $image[$i] = $i.".jpg"}  를 $image[$i] = $i.".jpg";} 로 수정했더니, syntax error는 사라졌는데, 다시 이미지가 깨지고 내용도 나오지 않는 1줄 상태로 복귀했습니다 ;;;;;;

if ($thumb['src']) {
  $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
} else {
  $img_content = '<img src="'.$board_skin_url.'/img/noimage_random/' . sprintf('%02d', rand(1, 90))  . '.jpg' . '" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
}
echo $img_content;


<?php
                    if (!$list[$i]['is_notice']) {
                        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
                        
           if ($thumb['src']) { 
  $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">'; 
} else { 
    
  $img_content = '<img src="'.$board_skin_url.'/img/noimage_random/' . sprintf('%02d', rand(1, 90))  . '.jpg' . '" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">'; 
} 
echo $img_content;
}


...이렇게 넣으면, 리스트는 제대로 나오지만 이미지가 없는 경우, 이미지가 나오지 않습니다.


그리고...



<?php
                    if (!$list[$i]['is_notice']) {
                        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height']);
                        
            if($thumb['src']) {
                            $img_content = '<img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">';
                        } else {
                            for($i=1;$i<=99;$i++) {
                               $image[$i] = $i.".jpg";}
                           $random = time()%count($image);

                         $img_content = '<img src="'.$board_skin_url.'/img/noimage_random/' . sprintf('%02d', rand(1, 90))  . '.jpg' . '" width="'.$board['bo_gallery_width'].'" height="'.$board['bo_gallery_height'].'" class="list_img">'; 
                        }
                        echo $img_content;
                    }



  for($i=1;$i<=99;$i++) {
                              $image[$i] = $i.".jpg";}
                          $random = time()%count($image);

을 넣으면, 이미지와 내용이 나오지 않는 1줄로 나옵니다.


for 문 자체에 뭔가 문제가 있는걸까요? ㅠㅠ

이런 방법으로는 제가 원하는 랜덤이미지가 안되는건지......

뭔가 다른 다른 방법으로 해야 하나봅니다 ㅠㅠ



문제가 해결 되지는 않았지만. 계속 봐주시고 수고해주신 슈와이님 정말 감사합니다!!!

답변을 작성하시기 전에 로그인 해주세요.
전체 23
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT