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

'|'로 시작하여 구분한 여분필드 데이터를 목록에서 불러오기 채택완료

그누구나 2년 전 조회 2,952

wr_10에 유튜브id를 '|'로 시작하여 각각의 id를 구분하여 여러 개를 저장합니다.

write 입력상태:

 

database 저장상태:

 

view에서는 이 유튜브 클립들을 아래 코드로 잘 표시되고 정상 작동합니다.

</p>

<p><?php if ($view['wr_10']) { 

    $wr_10x = explode("|",substr($view['wr_10'], 1));    

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

            $k=$i+1;

?></p>

<p><div class="video-container">

    <iframe width="100%" src="<a href="https://www.youtube.com/embed/<?php" target="_blank" rel="noopener noreferrer">https://www.youtube.com/embed/<?php</a> echo $wr_10x[$i]; ?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

</div>





<div id="bo_v_share">

</div>

<?php } } ?></p>

<p>

 

그런데, 이 클립들 가운데, 첫번째 클립을 list에 표시되고 실행되도록 하려는데, 잘 안되는군요.

view에서와 비슷하게 아래와 같이 짜집기를 해봤는데, 

Warning: Undefined array key 'wr_10' in .... 이라고 뜨네요.

편정 고수님들의 지도 바랍니다.

</p>

<p><?php if ($list['wr_10']) { 

    $wr_10x = explode("|",substr($list['wr_10'], 1));    

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

            $k=$i+1;</p>

<p>    if($$wr_10x[0]) {

        $img_content = '<img class="popup_youtube img-fluid" data-me_id="'.$list[$i]['wr_10'].'" src="<a href="https://img.youtube.com/vi/'.$wr_10x[0].'/maxresdefault.jpg"" target="_blank" rel="noopener noreferrer">https://img.youtube.com/vi/'.$wr_10x[0].'/maxresdefault.jpg"</a> alt="'.$list[$i]['subject'].'">';

    }else{

        /* 썸네일 이미지 */

        $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);

        if($thumb['alt']){

            $alt_txt = $thumb['alt'];

        }else{

            $alt_txt = $list[$i]['subject'];

        }

    if($thumb['src']) {

        $img_content = '<img src="'.$thumb['src'].'" data-big_img="'.$thumb['ori'].'" class="popup_imgview img-responsive img-rounded" alt="'.$alt_txt.'" >';

    } else {

        //$img_content = '<img class="img-fluid" src="<a href="http://placehold.it/700x300"" target="_blank" rel="noopener noreferrer">http://placehold.it/700x300"</a> alt="">';

        $img_content ='';

        }

    }</p>

<p>

    }

 ?></p>

<p>

 

 

 

 

 

 

 

 

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

답변 3개

채택된 답변
+20 포인트
2년 전

</p>

<p><?php

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

    if (empty($list[$i]['wr_10']) == false) { 

        $wr_10x = explode("|",substr($list[$i]['wr_10'], 1));

        

        for ($j = 0;  $j < count($wr_10x); $j++) {

            $k=$j+1;

            if($wr_10x[$j]) {

                $img_content = '<img class="popup_youtube img-fluid" data-me_id="'.$list[$i]['wr_10'].'" src="<a href="https://img.youtube.com/vi/'.$wr_10x[$j].'/maxresdefault.jpg"" target="_blank" rel="noopener noreferrer">https://img.youtube.com/vi/'.$wr_10x[$j].'/maxresdefault.jpg"</a> alt="'.$list[$i]['subject'].'">';

            }else{

                /* 썸네일 이미지 */

                $thumb = get_list_thumbnail($board['bo_table'], $list[$i]['wr_id'], $board['bo_gallery_width'], $board['bo_gallery_height'], false, true);

                if($thumb['alt']){

                    $alt_txt = $thumb['alt'];

                }else{

                    $alt_txt = $list[$i]['subject'];

                }

                if($thumb['src']) {

                    $img_content = '<img src="'.$thumb['src'].'" data-big_img="'.$thumb['ori'].'" class="popup_imgview img-responsive img-rounded" alt="'.$alt_txt.'" >';

                } else {

                    //$img_content = '<img class="img-fluid" src="<a href="http://placehold.it/700x300"" target="_blank" rel="noopener noreferrer">http://placehold.it/700x300"</a> alt="">';

                    $img_content ='';

                }

            }

        }

    }

}

?></p>

<p>

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

답변에 대한 댓글 1개

그누구나
2년 전
감사합니다. 경고 메시지 없이 썸네일을 잘 불러옵니다.

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

$wr10ex = explode('|', $list[$i]['wr_10']);
if($wr10ex[0]){ // wr_10 의 첫번째 배열이 있을경우
~~~~
} else {
~~~~
}

이렇게 해보세요.

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

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

M
2년 전

 

 

</p>

<pre>
<code><?php if ($list[$i]['wr_10']) { 
    $wr_10x = explode("|",substr($list[$i]['wr_10'], 1));    
 ?></code></pre>

<p>

이 부분에서 [$i]를 빼먹으셔서 그런거 같습니다.

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

답변에 대한 댓글 1개

그누구나
2년 전
여전히 애래와 같은 경고가 뜨면서 안되네요.

Warning: Undefined array key 6 in ...
Warning: Trying to access array offset on value of type null in ...

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

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

로그인