테스트 사이트 - 개발 중인 베타 버전입니다

for 문 문의 채택완료

아기강도 6년 전 조회 2,276

안녕하세요.

 

배너를 만들고 있는데 for 문에서 갯수를 끊어 나열하려 합니다

 

</p>

<div style="color: rgb(212, 212, 212); line-height: 19px; font-family: Consolas, "Courier New", monospace; font-size: 14px; font-weight: normal; white-space: pre; background-color: rgb(30, 30, 30);">
<div><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">class</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(206, 145, 120);">"pic_lt_bottom"</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">class</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(206, 145, 120);">"owl-carousel-bottom owl-theme"</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(86, 156, 214);"><?php</span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(197, 134, 192);">for</span><span style="color: rgb(212, 212, 212);"> (</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(181, 206, 168);">0</span><span style="color: rgb(212, 212, 212);">; </span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);"><</span><span style="color: rgb(220, 220, 170);">count</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(156, 220, 254);">$list</span><span style="color: rgb(212, 212, 212);">); </span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">++) {</span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(156, 220, 254);">$thumb</span><span style="color: rgb(212, 212, 212);"> = </span><span style="color: rgb(220, 220, 170);">get_list_thumbnail</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(156, 220, 254);">$bo_table</span><span style="color: rgb(212, 212, 212);">, </span><span style="color: rgb(156, 220, 254);">$list</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">][</span><span style="color: rgb(206, 145, 120);">'wr_id'</span><span style="color: rgb(212, 212, 212);">], </span><span style="color: rgb(156, 220, 254);">$thumb_width</span><span style="color: rgb(212, 212, 212);">, </span><span style="color: rgb(156, 220, 254);">$thumb_height</span><span style="color: rgb(212, 212, 212);">, </span><span style="color: rgb(86, 156, 214);">false</span><span style="color: rgb(212, 212, 212);">, </span><span style="color: rgb(86, 156, 214);">true</span><span style="color: rgb(212, 212, 212);">);</span></div>
 

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(197, 134, 192);">if</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(156, 220, 254);">$thumb</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(206, 145, 120);">'src'</span><span style="color: rgb(212, 212, 212);">]) {</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(156, 220, 254);">$img</span><span style="color: rgb(212, 212, 212);"> = </span><span style="color: rgb(156, 220, 254);">$thumb</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(206, 145, 120);">'src'</span><span style="color: rgb(212, 212, 212);">];</span></div>

<div><span style="color: rgb(212, 212, 212);">    } </span><span style="color: rgb(197, 134, 192);">else</span><span style="color: rgb(212, 212, 212);"> {</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(156, 220, 254);">$img</span><span style="color: rgb(212, 212, 212);"> = G5_IMG_URL</span><span style="color: rgb(212, 212, 212);">.</span><span style="color: rgb(206, 145, 120);">'/no_img.png'</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(156, 220, 254);">$thumb</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(206, 145, 120);">'alt'</span><span style="color: rgb(212, 212, 212);">] = </span><span style="color: rgb(206, 145, 120);">'이미지가 없습니다.'</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">    }</span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(156, 220, 254);">$img_content</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">] = </span><span style="color: rgb(206, 145, 120);">'<img src="'</span><span style="color: rgb(212, 212, 212);">.</span><span style="color: rgb(156, 220, 254);">$img</span><span style="color: rgb(212, 212, 212);">.</span><span style="color: rgb(206, 145, 120);">'" alt="'</span><span style="color: rgb(212, 212, 212);">.</span><span style="color: rgb(156, 220, 254);">$thumb</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(206, 145, 120);">'alt'</span><span style="color: rgb(212, 212, 212);">]</span><span style="color: rgb(212, 212, 212);">.</span><span style="color: rgb(206, 145, 120);">'" >'</span><span style="color: rgb(212, 212, 212);">;</span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">class</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(206, 145, 120);">"item"</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">            </span><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(86, 156, 214);">a</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">href</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(206, 145, 120);">"</span><span style="color: rgb(86, 156, 214);"><?php</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(220, 220, 170);">echo</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">$list</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">][</span><span style="color: rgb(206, 145, 120);">'href'</span><span style="color: rgb(212, 212, 212);">] </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span><span style="color: rgb(206, 145, 120);">"</span><span style="color: rgb(128, 128, 128);">></span><span style="color: rgb(86, 156, 214);"><?php</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(220, 220, 170);">echo</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">$img_content</span><span style="color: rgb(212, 212, 212);">[</span><span style="color: rgb(156, 220, 254);">$i</span><span style="color: rgb(212, 212, 212);">]; </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span><span style="color: rgb(128, 128, 128);"></</span><span style="color: rgb(86, 156, 214);">a</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">        </span><span style="color: rgb(128, 128, 128);"></</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(86, 156, 214);"><?php</span><span style="color: rgb(212, 212, 212);"> }  </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(86, 156, 214);"><?php</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(197, 134, 192);">if</span><span style="color: rgb(212, 212, 212);"> (</span><span style="color: rgb(220, 220, 170);">count</span><span style="color: rgb(212, 212, 212);">(</span><span style="color: rgb(156, 220, 254);">$list</span><span style="color: rgb(212, 212, 212);">) == </span><span style="color: rgb(181, 206, 168);">0</span><span style="color: rgb(212, 212, 212);">) { </span><span style="color: rgb(106, 153, 85);">//게시물이 없을 때  </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(128, 128, 128);"><</span><span style="color: rgb(86, 156, 214);">li</span><span style="color: rgb(212, 212, 212);"> </span><span style="color: rgb(156, 220, 254);">class</span><span style="color: rgb(212, 212, 212);">=</span><span style="color: rgb(206, 145, 120);">"empty_li"</span><span style="color: rgb(128, 128, 128);">></span><span style="color: rgb(212, 212, 212);">게시물이 없습니다.</span><span style="color: rgb(128, 128, 128);"></</span><span style="color: rgb(86, 156, 214);">li</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(212, 212, 212);">    </span><span style="color: rgb(86, 156, 214);"><?php</span><span style="color: rgb(212, 212, 212);"> }  </span><span style="color: rgb(86, 156, 214);">?</span><span style="color: rgb(86, 156, 214);">></span></div>

<div><span style="color: rgb(212, 212, 212);">  </span><span style="color: rgb(128, 128, 128);"></</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(128, 128, 128);">></span></div>

<div><span style="color: rgb(128, 128, 128);"></</span><span style="color: rgb(86, 156, 214);">div</span><span style="color: rgb(128, 128, 128);">></span></div>
</div>

<p>

<div class="item">

      <a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
 
for문 실행시 12개의 배너가 나오는데 6개씩 끊어서 놓으려고합니다
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a> - 처음부터 6번째까지
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a> - 6번째부터 12번째까지
</div>
 
위와같이 실행하려면 어떻게 해야할까요?
 
댓글을 작성하려면 로그인이 필요합니다.

답변 3개

채택된 답변
+20 포인트
세크티
6년 전
<?
$list = array('a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e','a', 'b', 'c', 'd', 'e');
$chunk = array_chunk($list, 6);
?>
<div class="pic_lt_bottom">
    <div class="owl-carousel-bottom owl-theme">
        <?php for ($i=0; $i<count($chunk); $i++) { ?>
            <div class="item">
                <?foreach ($chunk[$i] as $key=>$val){


                    $thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);

                    if($thumb['src']) {
                        $img = $thumb['src'];
                    } else {
                        $img = G5_IMG_URL.'/no_img.png';
                        $thumb['alt'] = '이미지가 없습니다.';
                    }
                    $img_content = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
                    ?>
                <a href="<?php echo $val['href'] ?>"><?php echo $img_content; ?></a>
                <?}?>
            </div>
        <?php }  ?>
        <?php if (count($list) == 0) { //게시물이 없을 때  ?>
            <div class="empty_li">게시물이 없습니다.</div>
        <?php }  ?>
    </div>
</div>
로그인 후 평가할 수 있습니다

답변에 대한 댓글 7개

아기강도
6년 전
알려주신 코드를 적용해보니
Illegal string offset 'wr_id' in 에러가 납니다 ㅠ
세크티
6년 전
에러코드 전문을 적어주시겠습니까?
아기강도
6년 전
에러부분중
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);
해당부분에서 에러가납니다 $val['wr_id']
세크티
6년 전
음..에러나는 php파일의 소스 전부를 부탁드립니다. 제 갤러리 스킨에서 $list를 chunk로 끊었을때는 wr_id가 제대로 출력이 되거든요.
아기강도
6년 전
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($list); $i++) {
$thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);

if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<div class="item">
<a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>

이렇게 입니다.
세크티
6년 전
<?php
if (!defined('_GNUBOARD_')) exit; // 개별 페이지 접근 불가
include_once(G5_LIB_PATH.'/thumbnail.lib.php');

// add_stylesheet('css 구문', 출력순서); 숫자가 작을 수록 먼저 출력됨
add_stylesheet('<link rel="stylesheet" href="'.$latest_skin_url.'/style.css">', 0);
$thumb_width = 386;
$thumb_height = 115;
$chunk_list = array_chunk($list,6);
?>
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.carousel.min.css">
<link rel="stylesheet" href="<?php echo $latest_skin_url;?>/owl.theme.default.min.css">
<script src="<?php echo $latest_skin_url;?>/owl.carousel.js"></script>
<div class="pic_lt_bottom">
<div class="owl-carousel-bottom owl-theme">
<?php
for ($i=0; $i<count($chunk_list); $i++) {

?>
<div class="item">
<?foreach ($chunk_list[$i] as $key=>$val){
$thumb = get_list_thumbnail($bo_table, $val['wr_id'], $thumb_width, $thumb_height, false, true);

if($thumb['src']) {
$img = $thumb['src'];
} else {
$img = G5_IMG_URL.'/no_img.png';
$thumb['alt'] = '이미지가 없습니다.';
}
$img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';
?>
<a href="<?php echo $val['href'] ?>"><?php echo $img_content[$i]; ?></a>
<?}?>
</div>
<?php } ?>
<?php if (count($list) == 0) { //게시물이 없을 때 ?>
<li class="empty_li">게시물이 없습니다.</li>
<?php } ?>
</div>
</div>
<script>
$(document).ready(function() {
var owl = $('.owl-carousel-bottom');
owl.owlCarousel({
loop: true,
margin: 20,
nav:false,
autoplay: true,
autoplayTimeout: 3000,
autoplayHoverPause: true,
responsiveClass:true,
responsive:{
0:{
items:1,
nav:false
},
500:{
items:2,
nav:false
},
1000:{
items:3,
nav:false,
}
}
});
// $('.play').on('click', function() {
// owl.trigger('play.owl.autoplay', [1000])
// })
// $('.stop').on('click', function() {
// owl.trigger('stop.owl.autoplay')
// })
})
</script>

이렇게 수정해보시겠어요. 크롬 디버거 켜보시면 div.item안에 ark 6개씩 들어갑니다.
아기강도
6년 전
아! 늦었지만 정말 감사드립니다! 덕분에 해결하였습니다 ㅠㅠ
많은도움 정말 감사드립니다! ㅠ

댓글을 작성하려면 로그인이 필요합니다.

jun31019
6년 전

</p>

<p>for ($i=0; $i<count($list); $i++) {

    $j = $i+1;    

    // 일반출력

    if($j%6 == 0){

        // 여섯번째마다

    }

}</p>

<p>

 

이렇게 하면 될거 같은데요 ^^;;

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

간단히 <br>로 끊었습니다.

 

</p>

<p><div class="pic_lt_bottom">

    <div class="owl-carousel-bottom owl-theme">

        <div class="item">

        <?php

        for ($i=0; $i<count($list); $i++) {

        $thumb = get_list_thumbnail($bo_table, $list[$i]['wr_id'], $thumb_width, $thumb_height, false, true);</p>

<p>        if($thumb['src']) {

            $img = $thumb['src'];

        } else {

            $img = G5_IMG_URL.'/no_img.png';

            $thumb['alt'] = '이미지가 없습니다.';

        }

        $img_content[$i] = '<img src="'.$img.'" alt="'.$thumb['alt'].'" >';

        ?>

            <a href="<?php echo $list[$i]['href'] ?>"><?php echo $img_content[$i]; ?></a>

        <?php

            if ($i=='5'){ echo '
'; }

        } 

        ?>

        <?php if (count($list) == 0) { //게시물이 없을 때  ?>

        게시물이 없습니다.

        <?php }  ?>

        </div>

    </div>

</div></p>

<p>

로그인 후 평가할 수 있습니다

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인