게시물 가로로 3개 출력 후 줄바꿈

게시물 가로로 3개 출력 후 줄바꿈

QA

게시물 가로로 3개 출력 후 줄바꿈

본문

총30개 게시물이 가로로 3개 출력 후 줄바꿈하여 10줄이 되게 하려는데요

 

게시물이 30번 반복되게 하였습니다

 

for ($i=0; $i<count($list); $i++) {
if ($i>0 && $i%$cols==0) {
    echo "<tr><td colspan='$cols' height='$space_h'></td></tr><tr>";
 }

 

요부분이 문제인 거 같은데요 어떻게 수정해야 할지

 

고수님들 부탁드립니다

 

아래 소스로 실행을 하면 출력되는 게시물이 30개가 넘고 출력이 엉망입니다

--------------------------------------------------------------------------------------

<? 
    // 반복되는 부분중에 그 특정내용 태그만 뽑아오기

    foreach ($xml->wanted as $obj) {
    $list[$i][wr_10] = $obj->company;   
    $list[$a][subject] = $obj->title;
    $ex2_filed[0] = $obj->region;
    $list[$i][wr_26] = $obj->salTpNm;
    $list[$i][wr_27] = $obj->minSal;
    $wnum[$a] = $obj->wantedAuthNo;
    $date_ymd = $obj->closeDt;

?>

<div class="job_latest_wrap">
    <table WIDTH="100%" border="0" summary="박스." cellspacing="0">
        <tbody valign="top">

<?php
for ($i=0; $i<count($list); $i++) {
if ($i>0 && $i%$cols==0) {
    echo "<tr><td colspan='$cols' height='$space_h'></td></tr><tr>";
 }

$gold_style = " style=\"display; border: solid 1px #2A8EF2;\"";
$subject_box = " style=\"border-top: solid 1px #2A8EF2; padding:3px 7px; background-color: #DCEFFF;\"";
?>

                <td width="<?php echo $col_width?>%" align="center">
                    <table WIDTH="<?php echo $box_w?>%" <?php echo $gold_style?> border="0" summary="박스." cellspacing="0">
                        <tbody valign="top">
                            <tr>
                                <td class="thumb_box" align='middle'>

                                    <?php
                                        if (preg_match("/\.(jpg|gif|png|bmp)$/i", $thumb) && file_exists($thumb)) {
                                            echo "<table width='100%' border='0' summary=\"로고, 회사명 박스.\" cellspacing='0'>";
                                            echo "<tr>";
                                            echo "<td style='height:{$img_h}px; text-align: center; border:0px solid #c7c7c7;'>";
                                            echo "<a href='{$list[$i]['href']}'><img src='$thumb' border='0' align='absmiddle'></a>";
                                            echo "</td>";
                                            echo "</tr></table>";


                                        }else if (!file_exists($list[$i][file_image0])){
                                            echo "<table width='100%' border='0' summary=\"로고 이미지가 아닐때, 회사명 박스.\" cellspacing='0'>";
                                            echo "<tr>";
                                            echo "<td style='height:{$img_h}px; text-align: center; border:0 solid #c7c7c7;'>";
                                            echo "<a href='{$list[$i]['href']}'><strong><blink><font color='#33CCFF'>{$list[$i][wr_10]}</font></blink></strong>";
                                            echo "</td>";
                                            echo "</tr></table>";
                                        }
                                    ?>

                                </td>
                            </tr>
                            <tr>

                                <td <?php echo $subject_box?>>
                                    <ul class="guin-content">
                                        <li class="wr_10"><a href="<?php echo $list[$i]['href']?>"><strong><?php echo cut_str($list[$i][wr_10],40);  //회사명 ?></strong></a></li>
                                        <li>

                                            <?php
                                                echo "<a href='{$list[$i]['href']}'>";
                                                echo "{$list[$i]['subject']}";
                                                echo "</a>";
                                                echo " " . $list[$i][icon_new];
                                            ?>

                                        </li>
                                        <!--<li>성별:<?php echo$list[$i][wr_11];  ?></li>-->
                                        <li>급여사항:<b><?php echo$list[$i][wr_26]; //급여사항 ?></b>
                                        <?php if ( $list[$i]['wr_27'] ==! null) { 
                                            echo "<b>";
                                            echo number_format($list[$i]['wr_27']) . "원";
                                            echo "</b>";
                                        } else {
                                            echo "<b>";
                                            echo$list[$i]['wr_29'];
                                            echo "</b>";} ?>
                                        </li>
                                        <li>근무지:<?//=cut_str($list[$i][wr_1],20,"") // 근무지 ?><?=$ex2_filed[0]?> <?=$ex2_filed[1]?>
<span style="float:right;">

                                            <?php //마감일
                                                $date_ymd = date(Y)."-".date(m)."-".date(d);
                                                if ($date_ymd <= $ext8_00) { //날짜를 구한다
                                                    echo "<img src='$latest_skin_path/img/icon_onf.gif' border='0' align='absmiddle'>";

                                                }else if ($ext8_01 == "상시모집") {
                                                     echo "<img src='$latest_skin_path/img/icon_on.gif' border='0' align='absmiddle'>";

                                                }else{ //구인완료
                                                    echo "<img src='$latest_skin_path/img/icon_off.gif' border='0' align='absmiddle'>";
                                                }
                                            ?>

</span>
                                        </li>
                                    </ul>

                                </td>
                            </tr>
                        </tbody>
                    </table>


                </td>

<?    } ?>
<?    } ?>

            </tr>
        </tbody>
    </table>
</div>

이 질문에 댓글 쓰기 :

답변 4


<? 
    // 반복되는 부분중에 그 특정내용 태그만 뽑아오기
$i = 0;
foreach ($xml->wanted as $obj) {
    $list[$i][wr_10] = $obj->company;   
    $list[$i][subject] = $obj->title;
    $list[$i][ex2_filed] = $obj->region;
    $list[$i][wr_26] = $obj->salTpNm;
    $list[$i][wr_27] = $obj->minSal;
    $list[$i][wnum] = $obj->wantedAuthNo;
    $list[$i][date_ymd] = $obj->closeDt;
    $i++;
}
?>
<div class="job_latest_wrap">
    <table WIDTH="100%" border="0" summary="박스." cellspacing="0">
        <tbody valign="top">
<?php
$cols = 3;
$gold_style = " style=\"display; border: solid 1px #2A8EF2;\"";
$subject_box = " style=\"border-top: solid 1px #2A8EF2; padding:3px 7px; background-color: #DCEFFF;\"";
for ($i=0; $i<count($list); $i++) {
    if ($i%$cols==0) {
        echo "<tr><td colspan='{$cols}' height='{$space_h}'></td></tr><tr>";
     }
?>                <td width="<?php echo $col_width?>%" align="center">
                    <table WIDTH="<?php echo $box_w?>%" <?php echo $gold_style?> border="0" summary="박스." cellspacing="0">
                        <tbody valign="top">
                            <tr>
                                <td class="thumb_box" align='middle'>
                                    <?php
                                        if (preg_match("/\.(jpg|gif|png|bmp)$/i", $thumb) && file_exists($thumb)) {
                                            echo "<table width='100%' border='0' summary=\"로고, 회사명 박스.\" cellspacing='0'>";
                                            echo "<tr>";
                                            echo "<td style='height:{$img_h}px; text-align: center; border:0px solid #c7c7c7;'>";
                                            echo "<a href='{$list[$i]['href']}'><img src='$thumb' border='0' align='absmiddle'></a>";
                                            echo "</td>";
                                            echo "</tr></table>";

                                        }else if (!file_exists($list[$i][file_image0])){
                                            echo "<table width='100%' border='0' summary=\"로고 이미지가 아닐때, 회사명 박스.\" cellspacing='0'>";
                                            echo "<tr>";
                                            echo "<td style='height:{$img_h}px; text-align: center; border:0 solid #c7c7c7;'>";
                                            echo "<a href='{$list[$i]['href']}'><strong><blink><font color='#33CCFF'>{$list[$i][wr_10]}</font></blink></strong>";
                                            echo "</td>";
                                            echo "</tr></table>";
                                        }
                                    ?>
                                </td>
                            </tr>
                            <tr>
                                <td <?php echo $subject_box?>>
                                    <ul class="guin-content">
                                        <li class="wr_10"><a href="<?php echo $list[$i]['href']?>"><strong><?php echo cut_str($list[$i][wr_10],40);  //회사명 ?></strong></a></li>
                                        <li>
                                            <?php
                                                echo "<a href='{$list[$i]['href']}'>";
                                                echo "{$list[$i]['subject']}";
                                                echo "</a>";
                                                echo " " . $list[$i][icon_new];
                                            ?>
                                        </li>
                                        <!--<li>성별:<?php echo$list[$i][wr_11];  ?></li>-->
                                        <li>급여사항:<b><?php echo$list[$i][wr_26]; //급여사항 ?></b>
                                        <?php if ( $list[$i]['wr_27'] ==! null) { 
                                            echo "<b>";
                                            echo number_format($list[$i]['wr_27']) . "원";
                                            echo "</b>";
                                        } else {
                                            echo "<b>";
                                            echo$list[$i]['wr_29'];
                                            echo "</b>";} ?>
                                        </li>
                                        <li>근무지:<?//=cut_str($list[$i][wr_1],20,"") // 근무지 ?><?=$ex2_filed[0]?> <?=$ex2_filed[1]?>
<span style="float:right;">
                                            <?php //마감일
                                                $date_ymd = date(Y)."-".date(m)."-".date(d);
                                                if ($date_ymd <= $ext8_00) { //날짜를 구한다
                                                    echo "<img src='$latest_skin_path/img/icon_onf.gif' border='0' align='absmiddle'>";
                                                }else if ($ext8_01 == "상시모집") {
                                                     echo "<img src='$latest_skin_path/img/icon_on.gif' border='0' align='absmiddle'>";
                                                }else{ //구인완료
                                                    echo "<img src='$latest_skin_path/img/icon_off.gif' border='0' align='absmiddle'>";
                                                }
                                            ?>
</span>
                                        </li>
                                    </ul>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </td>
<?
    if ($i%$cols==0){
        echo "</tr>";
    }
}
    if($i%$cols != 0){
        echo "</tr>";
    }
?>
        </tbody>
    </table>
</div>

이런식으로 2중 for문을 사용하지 마시고 상단에서 list를 정의해주고 하단에서 list를 불러서 3줄 단위로 쪼개면 될 듯 해요

for문 구조만 바꾼거라 데이터의 일부가 나오지 않겠지만 도움 되길 바랍니다.

팻시님께서 예전에 알려주신 팁입니다^^
참고하세요.

<table width="100%" border="0">
<?php 
$parts = 3; // 세덩어리씩 보여줄때
//$i 는 0 부터 시작하세요.
for ($i=0; $i<$list_count; $i++) {  
if($i % $parts == 0) echo "<tr>"; 
?>
<td><?=$list[$i]['subject']?></td>
<?php
if($i % $parts == ($parts-1)) echo "</tr>";
}
// 그리고 3의 배수로 딱 끝나지 않잖아요.
if($key % $parts != ($parts-1)) {
echo str_repeat("<td colspan='3'></td>", (($parts - ($i % $parts)) % $parts));
echo "</tr>";
}
?>
</table>

<tr>
  <td>a</td>
  <td>b</td>
  <td>c</td>
</tr>
<tr>
  <td>d</td>
  <td>e</td>
  <td>f</td>
</tr>
<tr>
  <td>g</td>
  <td>h</td>
  <td>i</td>
</tr>
......
<tr>
  <td>x</td>
  <td>y</td>
  <td>z</td>
</tr>

이런 식입니다

윗부분 소스입니다


-------------------------------------------------------------


<?php
if (!defined("_GNUBOARD_")) exit; // 개별 페이지 접근 불가

/*
 *    Ezjob  for Gnuboard4 skin
 *    Copyright 2012. 08. Ezjob.kr
 *    File Encoding: Korean(Euc-Kr)
 */


// $is_crop = 1;
// $is_crop    : 세로 높이가 $height를 넘을 때 crop 할 것인지를 결정
//                0 : crop 하지 않습니다
//                1 : 기본 crop
//                2 : 중간을 기준으로 crop
$col_width = (int)(100 / $cols);


//불당썸---------------------------------------------------------------//
//$img_w = 100; //표시할 이미지의 가로사이즈
$img_h = 40; //표시할 이미지의 세로사이즈
//$img_s  = 20;

//언샾마스트 퀄리티(썸 노이즈바지)
$filter[type] = 90;
$filter[arg1] = 100;
$filter[arg2] = 1;
$filter[arg3] = 2;

$data_path = $g4[path]."/data/file/$bo_table";
$thumb_path = $data_path.'/thumb';
$no_img = $latest_skin_path."/img/img_no.gif";

// 불당썸을 include
include_once("$g4[path]/lib/thumb.lib.php");
//불당썸---------------------------------------------------------------//

// 옵션 출력설정
//list($gold) = explode('/', $options);
$latest_options = explode(",", $options);

$skin_code = $bo_table.rand();
?>

<style type="text/css">
/*<!--<![CDATA[*/
@import url(<?=$latest_skin_path?>/style_latest.css);
/*]]>-->*/
</style>

<?
// 채용정보 url
$url = "http://openapi.work.go.kr/opi/opi/opia/wantedApi.do";
 
$var = "?authKey=********************&callTp=L&returnType=XML&startPage=1&display=9";
$data = file_get_contents($url . $var);
$xml  = simplexml_load_string($data);
?>

&display=9"; 이 부분이 9번 출력하라는 부분입니다

if($i == 2) echo '<tr><td></td></tr>';

그냥 3번째 (0부터 시작하니 2)에 단을 나누는거 하나 들어가면 될것 같은데요?

위 소스는 3번째 단을 강제로 <tr>로 끊는다는건데

위 CSS 에 맞게 수정하셔야죠 ㅎㅎ

답변을 작성하시기 전에 로그인 해주세요.
전체 123,528 | RSS
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT