채택완료

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

2023-09-23 (토) 13:27:32 3,577

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

write 입력상태:

3743821884_1695443560.8602.png

database 저장상태:

3743821884_1695442435.3566.png

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

Copy
<?php if ($view['wr_10']) { 
    $wr_10x = explode("|",substr($view['wr_10'], 1));    
    for ($i = 0;  $i < count($wr_10x); $i++) {
            $k=$i+1;
?>

<div class="video-container">
    <iframe width="100%" src="https://www.youtube.com/embed/<?php echo $wr_10x[$i]; ?>" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<br><br>
<div id="bo_v_share">
</div>
<?php } } ?>

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

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

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

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

Copy
<?php if ($list['wr_10']) { 
    $wr_10x = explode("|",substr($list['wr_10'], 1));    
    for ($i = 0;  $i < count($wr_10x); $i++) {
            $k=$i+1;

    if($$wr_10x[0]) {
        $img_content = '<img class="popup_youtube img-fluid" data-me_id="'.$list[$i]['wr_10'].'" src="https://img.youtube.com/vi/'.$wr_10x[0].'/maxresdefault.jpg" 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="http://placehold.it/700x300" alt="">';
        $img_content ='';
        }
    }


    }
 ?>

답변 3개 / 댓글 2개

채택된 답변
+20 포인트
Copy
<?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="https://img.youtube.com/vi/'.$wr_10x[$j].'/maxresdefault.jpg" 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="http://placehold.it/700x300" alt="">';
                    $img_content ='';
                }
            }
        }
    }
}
?>

답변에 대한 댓글 1개

감사합니다. 경고 메시지 없이 썸네일을 잘 불러옵니다.
2023-09-23 (토) 13:51:26

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

이렇게 해보세요.

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

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

답변에 대한 댓글 1개

여전히 애래와 같은 경고가 뜨면서 안되네요.

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

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