Copy
<div class="box-title">공지사항<a class="noticemore" href="http://www.webshow.kr"><i class="fa fa-plus"></i></a></div> <ul> <? $notice_row = sql_fetch("select count(*) as cnt from wp_g5_write where bo_table='notice' order by wr_id desc"); $notice_count = $notice_row[cnt]; $notice_sql = "select * from wp_g5_write where bo_table='notice' order by wr_id desc"; $notice_result = sql_query($notice_sql); for($i=0;$notice_row=sql_fetch_array($notice_result);$i++){?> <li>[<?=date("y/m/d",strtotime($notice_row[wr_datetime]))?>] <a href="
이렇게 되서 게시물 최근글을 반복 추출하게 되어 있는데요.
for문이 무한반복되고 있어서
for($i=0;$notice_row=sql_fetch_array($notice_result);$i++){?>
조건부분에 < 5를 걸고 싶은데 어떻게 걸어야 하나요.ㅠ
|
답변 3개
채택된 답변
+20 포인트
2016-03-17 (목) 22:51:08
for문 안에 if($i<5) break; 추가하세요.
2016-03-17 (목) 23:01:37
$maxcnt = ($notice_count>5) ? 5 : $notice_count;
for($i=0;$i<$maxcnt;$i++){
이렇게 고쳐서 해보세요.
2016-03-17 (목) 18:59:46
for($i=0; $i<$notice_count; $i++) {
근데 단순히 for만 돈다고 해서 결과가 나오고 그러진 않을 것 같네요.
답변을 작성하려면 로그인이 필요합니다.