[재질문!] 변수 홀수 / 짝수 호출방법

[재질문!] 변수 홀수 / 짝수 호출방법

QA

[재질문!] 변수 홀수 / 짝수 호출방법

본문

안녕하세요.. php와 그누보드를 열심히 공부한지 1개월 된 유저입니다

 

다름이 아니라, 최신글을 홀수, 짝수를 나눠서 불러오게 하고 있습니다(슬라이드를 2줄로 이용하기 위함)

 

그래서 이렇게 코드를 작성했습니다

 


 
    <?php for ($n=1; $n<count($list); $n+=2) { ?>
        <?php for ($i=0; $i<count($list); $i+=2) { ?>
            <div class="slider2 sbox">
                    <a href="<?php echo $list[$i]['href'] ?>">
                        <?php                
                            $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                            if($thumb['src']) {
                                $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$i]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                                } else {
                                $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                                }                
                            echo $img_content;                                                             
                        ?>
                    </a>
                    <div class="gy_cotent">
                        <strong><?php echo cut_str($list[$i]['subject'], 150, "..") ?></strong>
                    </div>

 
                    <a href="<?php echo $list[$n]['href'] ?>">
                        <?php                
                            $thumb = get_list_thumbnail($bo_table, $list[$n]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                            if($thumb['src']) {
                                $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$n]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                                } else {
                                $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                                }                
                            echo $img_content;                                                             
                        ?>
                    </a>
                    <div class="gy_cotent">
                        <strong><?php echo cut_str($list[$n]['subject'], 150, "..") ?></strong>
                    </div>
            </div>
        <?php } ?>
    <?php } ?>
 

 

근데 출력이 첫째줄 [i 라인]은 잘 됩니다.

0,2,4,6,8

 

근데 [n]라인이 이상합니다

 

1,1,1,3,3,3,5,5,5,7,7,7,9,9,9... 이렇게요

 

n라인도 잘 표시되게 할 수 있을까요?

 

http://viewit04.cafe24.com/

이 질문에 댓글 쓰기 :

답변 1

for문 안에 for문을 넣어서 생긴 문제입니다. 밖으로 빼주면 됩니다.

 


 
    <?php for ($n=1; $n<count($list); $n+=2) { ?>        
      <div class="slider2 sbox">
              <a href="<?php echo $list[$i]['href'] ?>">
                  <?php                
                      $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                      if($thumb['src']) {
                          $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$i]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                          } else {
                          $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                          }                
                      echo $img_content;                                                             
                  ?>
              </a>
              <div class="gy_cotent">
                  <strong><?php echo cut_str($list[$i]['subject'], 150, "..") ?></strong>
              </div>

              <a href="<?php echo $list[$n]['href'] ?>">
                  <?php                
                      $thumb = get_list_thumbnail($bo_table, $list[$n]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                      if($thumb['src']) {
                          $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$n]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                          } else {
                          $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                          }                
                      echo $img_content;                                                             
                  ?>
              </a>
              <div class="gy_cotent">
                  <strong><?php echo cut_str($list[$n]['subject'], 150, "..") ?></strong>
              </div>
      </div>        
    <?php } ?>
 
        <?php for ($i=0; $i<count($list); $i+=2) { ?>
            <div class="slider2 sbox">
                  <a href="<?php echo $list[$i]['href'] ?>">
                      <?php                
                          $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                          if($thumb['src']) {
                              $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$i]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                              } else {
                              $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                              }                
                          echo $img_content;                                                             
                      ?>
                  </a>
                  <div class="gy_cotent">
                      <strong><?php echo cut_str($list[$i]['subject'], 150, "..") ?></strong>
                  </div>

                  <a href="<?php echo $list[$n]['href'] ?>">
                      <?php                
                          $thumb = get_list_thumbnail($bo_table, $list[$n]['wr_id'], $imgmaxwidth, $imgmaxheight);                                    
                          if($thumb['src']) {
                              $img_content = '<a rel="gallery"  class="pirobox_gall" href="'.$thumb['src'].'" title="'.$list[$n]['subject'].'" width="'.$imgmaxwidth.'" height="'.$imgmaxheight.'"><img src="'.$thumb['src'].'" alt="'.$thumb['alt'].'" width="'.$imgminwidth.'" height="'.$imgminheight.'"></a>';
                              } else {
                              $img_content = '<span style="width:'.$board['bo_gallery_width'].'px;height:'.$board['bo_gallery_height'].'px">no image</span>';
                              }                
                          echo $img_content;                                                             
                      ?>
                  </a>
                  <div class="gy_cotent">
                      <strong><?php echo cut_str($list[$n]['subject'], 150, "..") ?></strong>
                  </div>
          </div>
        <?php } ?>
답변을 작성하시기 전에 로그인 해주세요.
전체 448
QA 내용 검색

회원로그인

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