리스트 페이지에서 첨부파일을 아래 소스 처럼 불러오게 되면 첨부파일 갯수를 일정하게 해야되는데
반복문으로 해서 첨부된 파일들만 불러오게 하고 싶습니다.
초보자라 반복문으로 만들기가 쉽지가 않습니다.
혹시 가능하신분 알려주시면 정말 감사하겠습니다.
Copy
<?php if ($is_good) { ?><li><span class="gall_subject">추천</span><strong><?php echo $list[$i]['wr_good'] ?></strong></li><?php } ?>
<?php if ($is_nogood) { ?><li><span class="gall_subject">비추천</span><strong><?php echo $list[$i]['wr_nogood'] ?></strong></li><?php } ?>
</ul>
</li>
<!-- 여기서 부터 반복문 시작 -->
<div style="display: none;">
<a href="<?echo $list[$i]['file'][1]["path"]."/".$list[$i]['file'][1]["file"];?>"></a>
<a href="<?echo $list[$i]['file'][2]["path"]."/".$list[$i]['file'][2]["file"];?>"></a>
<a href="<?echo $list[$i]['file'][3]["path"]."/".$list[$i]['file'][3]["file"];?>"></a>
</div>
<!-- 여기가 반복문 끝 -->
<?php } ?>
<?php if (count($list) == 0) { echo "<li class=\"empty_list\">게시물이 없습니다.</li>"; } ?>
</ul>
답변 3개
채택된 답변
+20 포인트
2017-10-18 (수) 22:28:41
Copy
<!-- 여기서 부터 반복문 시작 -->
<div style="display: none;">
<a href="<?echo $list[$i]['file'][1]["path"]."/".$list[$i]['file'][1]["file"];?>"></a>
<a href="<?echo $list[$i]['file'][2]["path"]."/".$list[$i]['file'][2]["file"];?>"></a>
<a href="<?echo $list[$i]['file'][3]["path"]."/".$list[$i]['file'][3]["file"];?>"></a>
</div>
<!-- 여기가 반복문 끝 -->
위의 코드라고 인식하고
Copy
<!-- 여기서 부터 반복문 시작 -->
<div style="display: none;">
<?php
for ($j = 1; $j <= 3; $j++) {
if ($list[$i]['file'][$j]['file']) { ?>
<a href="<?echo $list[$i]['file'][$j]['path']."/".$list[$i]['file'][$j]['file'];?>"><?php echo $list[$i]['file'][$j]['file'];?></a>
<?php }
}
?>
</div>
<!-- 여기가 반복문 끝 -->
2017-10-18 (수) 22:53:07
두분 답변 감사드립니다.
그림자 밟기님 소스로는 원래 첨부 파일보다 빈값으로 2개가 더 생기네요.
플래토님 소스로 정확하게 첨부파일 갯수 만큼 나타납니다.
두분 모두 감사드립니다.
Copy
<!-- 여기서 부터 반복문 시작 -->
<div style="display: none;">
<?php for($j = 1; $j <= count($list[$i]['file']); $j++) { ?>
<a href="<?php echo $list[$i]['file'][$j]["path"]."/".$list[$i]['file'][$j]["file"];?>"></a>
<?php } ?>
</div>
<!-- 여기가 반복문 끝 -->
답변을 작성하려면 로그인이 필요합니다.