최신글 배열문제입니다. 정보
최신글 배열문제입니다.본문
안녕하세요!
매번 많은 도움을 얻어갑니다.
며칠동안 질답게시판을 통해 방법을 찾아봤지만 적용이 잘 안되어 이렇게 직접 올려봅니다.
아래는 최신글 스킨입니다. 현재는 세로로 5개가 출력되고 있습니다.
최신글을 가로 2개 세로 2개로 출력하고 싶은데 어디를 손봐야 할까요?
1 2
3 4
이렇게 출력하고 싶습니다.
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if(!$options) $options=2;
$cols = $options; // 이미지 가로갯수 // 이미지 세로 갯수는 메인에서 지정(총 이미지 수)
$image_h = 12; // 이미지 상하 간격
$col_width = (int)(99 / $cols);
?>
<link rel="stylesheet" href="<?=$latest_skin_path?>/style.css" type="text/css" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" valign="top" STYLE='MARGIN:0PX 0PX 0PX 0PX; display:inline;'>
<tr>
<td align='center'>
<table width="100%" border="0" cellspacing="0" cellpadding="0" valign="top">
<?
//여러 메뉴들의 최신글 5개 추출
$sql = "select * from (
SELECT w.*, 'food' AS bo_table,f.bf_file FROM nsb_write_food w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='food'
WHERE w.wr_is_comment =0
union
SELECT w.*,'shopping' AS bo_table,f.bf_file FROM nsb_write_shopping w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='shopping'
WHERE w.wr_is_comment =0
union
SELECT w.*,'sightseeing' AS bo_table,f.bf_file FROM nsb_write_sightseeing w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='sightseeing'
WHERE w.wr_is_comment =0
union
SELECT w.*,'hotel' AS bo_table,f.bf_file FROM nsb_write_hotel w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='hotel'
WHERE w.wr_is_comment =0
union
SELECT w.*,'tour' AS bo_table,f.bf_file FROM nsb_write_tour w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='tour'
WHERE w.wr_is_comment =0
union
SELECT w.*,'beauty' AS bo_table,f.bf_file FROM nsb_write_beauty w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='beauty'
WHERE w.wr_is_comment =0
union
SELECT w.*,'clinic' AS bo_table,f.bf_file FROM nsb_write_clinic w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='clinic'
WHERE w.wr_is_comment =0
)a order by a.wr_datetime desc limit 0,5";
$result = sql_query($sql);
$cnt_list = @mysql_num_rows($result);
for ($i=0; $i<$cnt_list; $i++) {
$data_list = sql_fetch_array($result);
?>
</tr>
<tr>
<td width="<?=$col_width?>%" align="center" height="75">
<?
$data_path = $g4[path]."/data/file/".$data_list[bo_table];
$thumb_path = $data_path.'/thumb';
$image = $data_list[bf_file]; //원본
$img=$data_path. "/".$image; //썸네일이 없을경우 원본출력
$thumb = $thumb_path. "/". $data_list[wr_id];
if ( file_exists($thumb) ){
$img = $thumb;
}
if($image==""){
$img = "/home/shop/img/no_image.gif";
}
$style = "style='font-family:sans-serif; font-weight:bold; color:#244d79;' ";
/*
if ($list[$i][icon_new]) {
$style = "style='font-family:돋움; font-size:9pt; color:#134980;' ";
}
*/
$subject = "<span $style>".conv_subject($data_list[wr_subject], 34, "…")."</span>"; //제목 글자수 자르기
$wr_hit = $data_list[wr_hit];
$wr_id = $data_list[wr_id];
// if ($list[$i]['comment_cnt']) //코
// $cmt = "({$list[$i]['comment_cnt']})";
$bg = ""; //새글?
if ($list[$i][icon_new]){
$bg="la_top_2.gif";
}else{
$bg="la_top_1.gif";
}
echo $list[$i][icon_reply] . " ";
$bo_table = $data_list[bo_table];
if($bo_table == "food") $bo_name = "";
else if($bo_table == "shopping") $bo_name = "";
else if($bo_table == "sightseeing") $bo_name = "";
else if($bo_table == "hotel") $bo_name = "";
else if($bo_table == "tour") $bo_name = "";
else if($bo_table == "beauty") $bo_name = "";
else if($bo_table == "clinic") $bo_name = "";
?>
<table cellpadding='0' cellspacing='0' border='0' width="100%" valign="top">
<tr>
<td valign='top' align='center' style="padding-top:3px" >
<a href="<?=$g4[bbs_path]?>/board.php?bo_table=<?=$data_list[bo_table]?>&wr_id=<?=$wr_id?>" onFocus="this.blur();" title="<?=conv_subject($data_list[wr_subject], 40, '…')?>">
<img src='<?=$img?>' width='110' height='65' border='1' style='border:1 solid #B2BAEE'></a>
</td>
<td width="170" valign="top">
<table cellpadding='0' cellspacing='0' border='0' width="100%" valign="top">
<tr>
<td align="left"><? if($data_list['ca_name']){ ?>[<?=$data_list['ca_name']?>]<b><? }?> <?=$bo_name?></b></td>
</tr>
<tr>
<td align="left">
<a href="<?=$g4[bbs_path]?>/board.php?bo_table=<?=$data_list[bo_table]?>&wr_id=<?=$wr_id?>" onFocus="this.blur();" title="<?=conv_subject($data_list[wr_subject], 40, '…')?>"><?=$subject?></a></td>
</tr>
<tr>
<td align="left">
<span style='color:#db0000;'><b><? if ($data_list[wr_82]) {echo $data_list[wr_82]." / ";}?><? if ($data_list[wr_84]) { echo $data_list[wr_84].""; }?></b></span>
</td>
</tr>
<tr>
<td align="left"><?=date("y-m-d", strtotime($data_list[wr_datetime]))?> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<? } ?>
<? if ($cnt_list == 0) { echo "<td height=80 align=center>게시물이 없습니다.</td>"; } ?>
</table>
</td>
</tr>
</table>
매번 많은 도움을 얻어갑니다.
며칠동안 질답게시판을 통해 방법을 찾아봤지만 적용이 잘 안되어 이렇게 직접 올려봅니다.
아래는 최신글 스킨입니다. 현재는 세로로 5개가 출력되고 있습니다.
최신글을 가로 2개 세로 2개로 출력하고 싶은데 어디를 손봐야 할까요?
1 2
3 4
이렇게 출력하고 싶습니다.
<?
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가
if(!$options) $options=2;
$cols = $options; // 이미지 가로갯수 // 이미지 세로 갯수는 메인에서 지정(총 이미지 수)
$image_h = 12; // 이미지 상하 간격
$col_width = (int)(99 / $cols);
?>
<link rel="stylesheet" href="<?=$latest_skin_path?>/style.css" type="text/css" />
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" valign="top" STYLE='MARGIN:0PX 0PX 0PX 0PX; display:inline;'>
<tr>
<td align='center'>
<table width="100%" border="0" cellspacing="0" cellpadding="0" valign="top">
<?
//여러 메뉴들의 최신글 5개 추출
$sql = "select * from (
SELECT w.*, 'food' AS bo_table,f.bf_file FROM nsb_write_food w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='food'
WHERE w.wr_is_comment =0
union
SELECT w.*,'shopping' AS bo_table,f.bf_file FROM nsb_write_shopping w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='shopping'
WHERE w.wr_is_comment =0
union
SELECT w.*,'sightseeing' AS bo_table,f.bf_file FROM nsb_write_sightseeing w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='sightseeing'
WHERE w.wr_is_comment =0
union
SELECT w.*,'hotel' AS bo_table,f.bf_file FROM nsb_write_hotel w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='hotel'
WHERE w.wr_is_comment =0
union
SELECT w.*,'tour' AS bo_table,f.bf_file FROM nsb_write_tour w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='tour'
WHERE w.wr_is_comment =0
union
SELECT w.*,'beauty' AS bo_table,f.bf_file FROM nsb_write_beauty w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='beauty'
WHERE w.wr_is_comment =0
union
SELECT w.*,'clinic' AS bo_table,f.bf_file FROM nsb_write_clinic w
left join nsb_board_file f on w.wr_id=f.wr_id and f.bo_table='clinic'
WHERE w.wr_is_comment =0
)a order by a.wr_datetime desc limit 0,5";
$result = sql_query($sql);
$cnt_list = @mysql_num_rows($result);
for ($i=0; $i<$cnt_list; $i++) {
$data_list = sql_fetch_array($result);
?>
</tr>
<tr>
<td width="<?=$col_width?>%" align="center" height="75">
<?
$data_path = $g4[path]."/data/file/".$data_list[bo_table];
$thumb_path = $data_path.'/thumb';
$image = $data_list[bf_file]; //원본
$img=$data_path. "/".$image; //썸네일이 없을경우 원본출력
$thumb = $thumb_path. "/". $data_list[wr_id];
if ( file_exists($thumb) ){
$img = $thumb;
}
if($image==""){
$img = "/home/shop/img/no_image.gif";
}
$style = "style='font-family:sans-serif; font-weight:bold; color:#244d79;' ";
/*
if ($list[$i][icon_new]) {
$style = "style='font-family:돋움; font-size:9pt; color:#134980;' ";
}
*/
$subject = "<span $style>".conv_subject($data_list[wr_subject], 34, "…")."</span>"; //제목 글자수 자르기
$wr_hit = $data_list[wr_hit];
$wr_id = $data_list[wr_id];
// if ($list[$i]['comment_cnt']) //코
// $cmt = "({$list[$i]['comment_cnt']})";
$bg = ""; //새글?
if ($list[$i][icon_new]){
$bg="la_top_2.gif";
}else{
$bg="la_top_1.gif";
}
echo $list[$i][icon_reply] . " ";
$bo_table = $data_list[bo_table];
if($bo_table == "food") $bo_name = "";
else if($bo_table == "shopping") $bo_name = "";
else if($bo_table == "sightseeing") $bo_name = "";
else if($bo_table == "hotel") $bo_name = "";
else if($bo_table == "tour") $bo_name = "";
else if($bo_table == "beauty") $bo_name = "";
else if($bo_table == "clinic") $bo_name = "";
?>
<table cellpadding='0' cellspacing='0' border='0' width="100%" valign="top">
<tr>
<td valign='top' align='center' style="padding-top:3px" >
<a href="<?=$g4[bbs_path]?>/board.php?bo_table=<?=$data_list[bo_table]?>&wr_id=<?=$wr_id?>" onFocus="this.blur();" title="<?=conv_subject($data_list[wr_subject], 40, '…')?>">
<img src='<?=$img?>' width='110' height='65' border='1' style='border:1 solid #B2BAEE'></a>
</td>
<td width="170" valign="top">
<table cellpadding='0' cellspacing='0' border='0' width="100%" valign="top">
<tr>
<td align="left"><? if($data_list['ca_name']){ ?>[<?=$data_list['ca_name']?>]<b><? }?> <?=$bo_name?></b></td>
</tr>
<tr>
<td align="left">
<a href="<?=$g4[bbs_path]?>/board.php?bo_table=<?=$data_list[bo_table]?>&wr_id=<?=$wr_id?>" onFocus="this.blur();" title="<?=conv_subject($data_list[wr_subject], 40, '…')?>"><?=$subject?></a></td>
</tr>
<tr>
<td align="left">
<span style='color:#db0000;'><b><? if ($data_list[wr_82]) {echo $data_list[wr_82]." / ";}?><? if ($data_list[wr_84]) { echo $data_list[wr_84].""; }?></b></span>
</td>
</tr>
<tr>
<td align="left"><?=date("y-m-d", strtotime($data_list[wr_datetime]))?> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
<? } ?>
<? if ($cnt_list == 0) { echo "<td height=80 align=center>게시물이 없습니다.</td>"; } ?>
</table>
</td>
</tr>
</table>
댓글 전체

html출력부분을 이런형태로 바꿔보세요
<?
$cols = 2;//2단으로 나누겠음
?>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<?
for ($i=0; $i<count($list); $i++) {
if ($i>0 && $i%$cols==0)
echo "</tr><tr>";
echo "<td>";
echo "<table cellpadding=0 cellspacing=0 >";
echo "<tr><td>";
echo "<img src='이미지' border=0>";
echo "</td></tr>";
echo "</table></td>\n";
}
// 나머지 td
$cnt = $i%$cols;
if ($cnt)
for ($i=$cnt; $i<$cols; $i++)
echo "<td> </td>";
?>
</tr>
</table>
<?
$cols = 2;//2단으로 나누겠음
?>
<table width=100% cellpadding=0 cellspacing=0 border=0>
<tr>
<?
for ($i=0; $i<count($list); $i++) {
if ($i>0 && $i%$cols==0)
echo "</tr><tr>";
echo "<td>";
echo "<table cellpadding=0 cellspacing=0 >";
echo "<tr><td>";
echo "<img src='이미지' border=0>";
echo "</td></tr>";
echo "</table></td>\n";
}
// 나머지 td
$cnt = $i%$cols;
if ($cnt)
for ($i=$cnt; $i<$cols; $i++)
echo "<td> </td>";
?>
</tr>
</table>
말씀하신 대로 해봤는데 배열은 원하는대로 나오지만 그 결과가 엉망이네요.
배열만이 문제가 아니었나 봅니다.
원하는 결과를 얻으려면 더 들여다 봐야 하겠습니다.
제가 원했던 답은 명쾌하게 주셨습니다. 친절한 답변 고맙습니다. ^^
배열만이 문제가 아니었나 봅니다.
원하는 결과를 얻으려면 더 들여다 봐야 하겠습니다.
제가 원했던 답은 명쾌하게 주셨습니다. 친절한 답변 고맙습니다. ^^