최근게시글 2열? 2줄? 로 출력하기 정보
최근게시글 2열? 2줄? 로 출력하기본문
최근게시글을 2열? 2줄? 로 출력하는 방법을 검색해서 얻은 방법으로 작업해보았습니다.
작업 결과는
1 2
3 4
5 6
7 8
9 10
위와 같이 최근게시글이 출력이 되었습니다.
echo "</tr><tr>";
를 넣는 방식으로 2개가 출력되면 아래로 떨어트리는 for 문이더군요.
그런데, 제가 원하는 출력은 저 방식이 아니었습니다.
1 6
2 7
3 8
4 9
5 10
위와 같이 출력되길 원합니다.
이 방법을 처리하자니 너무 헷갈리고 잘 안되네요.
실험삼아 했더니..
1
2
3
4
5
6
위 처럼.. 테이블이 뻑 나버립니다.
최근게시글을 위 방법처럼 출력시킬려면 어떻게 작성하면 되는지 해법 좀 알려주세요.
이거 때문에 한참을 헤매고 있네요.. ㅜ0ㅜ
작업 결과는
1 2
3 4
5 6
7 8
9 10
위와 같이 최근게시글이 출력이 되었습니다.
echo "</tr><tr>";
를 넣는 방식으로 2개가 출력되면 아래로 떨어트리는 for 문이더군요.
그런데, 제가 원하는 출력은 저 방식이 아니었습니다.
1 6
2 7
3 8
4 9
5 10
위와 같이 출력되길 원합니다.
이 방법을 처리하자니 너무 헷갈리고 잘 안되네요.
실험삼아 했더니..
1
2
3
4
5
6
위 처럼.. 테이블이 뻑 나버립니다.
최근게시글을 위 방법처럼 출력시킬려면 어떻게 작성하면 되는지 해법 좀 알려주세요.
이거 때문에 한참을 헤매고 있네요.. ㅜ0ㅜ
댓글 전체
for문은 제대로 돌고 있는데 제대로 열고 닫지를 못하네요.
소스를 첨부하면 답변이
바로 달릴듯 합니다.
소스를 첨부하면 답변이
바로 달릴듯 합니다.
예제를 만들어 보았습니다.
■ 미리보기 주소
http://dooraei.com/pf/test/latest_td2.php?bo_table=php&rows=10
■ 소스코드 (latest.skin.php)
======================================================================
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<?
$td_count = 2;
$list_count = count($list);
$td_width = 100 / $td_count;
for ($i=0, $row_num=0; $i<$list_count; $i++) {
if ($i%$td_count==0) {
$index = $i - $row_num;
$row_num++;
if ($i) echo "</tr><tr>";
}
else
$index = ceil( ($list_count/$td_count)+$i - $row_num);
?>
<td colspan=4 align=center width="<?=$td_width?>%">
<table width=95%>
<tr>
<td height=25>
<?
echo ($index+1) . ". ";
echo "<a href='{$list[$index]['href']}'>";
echo "{$list[$index]['subject']}";
echo "</a>";
if ($list[$index]['comment_cnt'])
echo " <a href=\"{$list[$index]['comment_href']}\"><span style='font-family:돋움; font-size:8pt; color:#9A9A9A;'>{$list[$index]['comment_cnt']}</span></a>";
?></td>
</tr>
<tr><td bgcolor=#EBEBEB height=1></td></tr>
</table>
</td>
<?
} // end for
$cnt = $i%$td_count;
if ($cnt) {
for ($i=$cnt; $i<$td_count; $i++)
echo "<td> </td>";
}
?>
</tr>
</table>
<? if (count($list) == 0) { ?><tr><td colspan=4 align=center height=50><font color=#6A6A6A>게시물이 없습니다.</a></td></tr><? } ?>
</table>
======================================================================
■ 미리보기 주소
http://dooraei.com/pf/test/latest_td2.php?bo_table=php&rows=10
■ 소스코드 (latest.skin.php)
======================================================================
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
?>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<?
$td_count = 2;
$list_count = count($list);
$td_width = 100 / $td_count;
for ($i=0, $row_num=0; $i<$list_count; $i++) {
if ($i%$td_count==0) {
$index = $i - $row_num;
$row_num++;
if ($i) echo "</tr><tr>";
}
else
$index = ceil( ($list_count/$td_count)+$i - $row_num);
?>
<td colspan=4 align=center width="<?=$td_width?>%">
<table width=95%>
<tr>
<td height=25>
<?
echo ($index+1) . ". ";
echo "<a href='{$list[$index]['href']}'>";
echo "{$list[$index]['subject']}";
echo "</a>";
if ($list[$index]['comment_cnt'])
echo " <a href=\"{$list[$index]['comment_href']}\"><span style='font-family:돋움; font-size:8pt; color:#9A9A9A;'>{$list[$index]['comment_cnt']}</span></a>";
?></td>
</tr>
<tr><td bgcolor=#EBEBEB height=1></td></tr>
</table>
</td>
<?
} // end for
$cnt = $i%$td_count;
if ($cnt) {
for ($i=$cnt; $i<$td_count; $i++)
echo "<td> </td>";
}
?>
</tr>
</table>
<? if (count($list) == 0) { ?><tr><td colspan=4 align=center height=50><font color=#6A6A6A>게시물이 없습니다.</a></td></tr><? } ?>
</table>
======================================================================
아.. td 제어를 처리하면 되는군요.
방법을 이해 했습니다.
정말 감사합니다!
방법을 이해 했습니다.
정말 감사합니다!