sub 페이지가 열릴 때 마다 mt_rand()를 이용하여 나오게 할 수 있을까요?

sub 페이지가 열릴 때 마다 mt_rand()를 이용하여 나오게 할 수 있을까요?

QA

sub 페이지가 열릴 때 마다 mt_rand()를 이용하여 나오게 할 수 있을까요?

본문

아래 그림처럼 Main Page(index)일 때는 좌우측배너가 side1, side2가 나오도록 하고

나머지는 모두 side3, side4 페이지가 나오도록 하였습니다. 

 

 

 

아래 코드로 출력을 하면 페이지 오픈 때마다 랜덤값이 출력되는데요

<?php  echo  'mt_rand(1, 4) : '.mt_rand(1, 4).'<br>'; ?>

 

mt_rand(1,4) 이 함수를 이용하면 될듯한데 어떻게 적용을 하면 될까요?

 

594048ebeab93c7c2675d40f01267df4_1487729914_0305.png
 

 

 


<?php if(defined('_INDEX_')) { // index에서만 실행 ?>
<div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side2.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side1.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<?php } else { ?>
<div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side3.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side4.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<?php } ?>

이 질문에 댓글 쓰기 :

답변 1

혹시 서브 페이지에서는 side1 ~ side4까지 랜덤하게 나오게 하신다는 건가요?

이렇게 하면 어떨까요~

 


<?php
$banner = array(2, 1);
if (!defined('_INDEX_')) {
 $banner = array();
 while (count($banner) < 2) {
  $index = mt_rand(1, 4);
  if (!in_array($index, $banner)) {
   $banner[] = $index;
  }
 }
}
?>
<div style="position:absolute; width:160px; left:50%; margin-left:-710px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side<?=$banner[0]?>.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe>
</div>
<div style="position:absolute; width:160px; left:50%; margin-left:580px; margin-top:55px; z-index:999;">
   <iframe src="/banner/side<?=$banner[1]?>.html" width="160" height="600" scrolling="no" frameborder="0" marginwidth="0" marginheight="0"></iframe> 
 
답변을 작성하시기 전에 로그인 해주세요.
전체 0 | RSS
QA 내용 검색
  • 개별 목록 구성 제목 답변작성자조회작성일
  • 질문이 없습니다.

회원로그인

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