관리자 페이지 최근 글 수정

불당   
   조회 10952   추천 0     비추천 0    

오늘 관리자 페이지 들어가다가 DB 서버가 주글 뻔 했습니다. ㅠㅠ...
그래서 다시 문제가 되는 SQL을 찾고 찬찬히 디볐습니다.
OMG.
이럴 수가 없습니다.
무려 3개의 거대 테이블 join을 그냥 냅뒀던 것 입니다.
어디선가 많이 본 코드 입니다.
join 필요 없게 코드 만들었습니다 (불당팩에만 있는 몇개 필드 썼습니다)
아주 속도 빠릅니다.
 
(수정후)
 
<?
// 최근 게시물 $new_write_rows 건을 구합니다
$sql_common = " from $g4[board_new_table] ";
$sql_common .= " where wr_is_comment = '0' ";
$sql_order = " order by bn_id desc ";
$colspan = 5;
?>
<br><br>
<?=subtitle("최근게시물", "$g4[bbs_path]/new.php");?>
<table width=100% cellpadding=0 cellspacing=1>
<input type=hidden name=sst  value='<?=$sst?>'>
<input type=hidden name=sod  value='<?=$sod?>'>
<input type=hidden name=sfl  value='<?=$sfl?>'>
<input type=hidden name=stx  value='<?=$stx?>'>
<input type=hidden name=page value='<?=$page?>'>
<colgroup width=100>
<colgroup width=100>
<colgroup width=''>
<colgroup width=80>
<colgroup width=80>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td>그룹</td>
    <td>게시판</td>
    <td>제목</td>
    <td>이름</td>
    <td>일시</td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<?
$sql = " select *
          $sql_common
          $sql_order
          limit $new_write_rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
    $tmp_write_table = $g4['write_prefix'] . $row['bo_table'];
    $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
    $name = get_sideview($row2['mb_id'], cut_str($row2['wr_name'], $config['cf_cut_name']), $row2['wr_email'], $row2['wr_homepage']);
    $datetime = get_datetime($row2['wr_datetime']);
    $bo = get_board($row[bo_table], "bo_subject");
    $bo_subject = cut_str($bo[bo_subject], 20);
    $gr = get_group($row[gr_id], "gr_subject");
    $gr_subject = cut_str($gr['gr_subject'],10);
    $list = $i%2;
    echo "
    <tr class='list$list col1 ht center'>
        <td class=small><a href='$g4[bbs_path]/new.php?gr_id=$row[gr_id]'>".$gr_subject."</a></td>
        <td class=small><a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]'>".$bo_subject."</a></td>
        <td align=left style='word-break:break-all;'>&nbsp;<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]'>".conv_subject($row2['wr_subject'], 100)."</a></td>
        <td>$name</td>
        <td>$datetime</td>
    </tr> "; 
}
if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>";
echo "<tr><td colspan='$colspan' class='line2'></td></tr>";
echo "</table>";
?>
 
(수정전)
 
<?
//$sql_common = " from $g4[board_new_table] a, $g4[board_table] b, $g4[group_table] c where a.bo_table = b.bo_table and b.gr_id = c.gr_id and b.bo_use_search = '1' ";
$sql_common = " from $g4[board_new_table] a, $g4[board_table] b, $g4[group_table] c where a.bo_table = b.bo_table and b.gr_id = c.gr_id ";
if (isset($gr_id))
    $sql_common .= " and b.gr_id = '$gr_id' ";
if (isset($view)) {
    if ($view == "w")
        $sql_common .= " and a.wr_id = a.wr_parent ";
    else if ($view == "c")
        $sql_common .= " and a.wr_id <> a.wr_parent ";
}
$sql_order = " order by a.bn_id desc ";
$sql = " select count(*) as cnt $sql_common ";
$row = sql_fetch($sql);
$total_count = $row['cnt'];
$colspan = 5;
?>
<br><br>
<?=subtitle("최근게시물 {$new_write_rows}건", "$g4[bbs_path]/new.php");?>
<table width=100% cellpadding=0 cellspacing=1>
<input type=hidden name=sst  value='<?=$sst?>'>
<input type=hidden name=sod  value='<?=$sod?>'>
<input type=hidden name=sfl  value='<?=$sfl?>'>
<input type=hidden name=stx  value='<?=$stx?>'>
<input type=hidden name=page value='<?=$page?>'>
<colgroup width=100>
<colgroup width=100>
<colgroup width=''>
<colgroup width=80>
<colgroup width=80>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td>그룹</td>
    <td>게시판</td>
    <td>제목</td>
    <td>이름</td>
    <td>일시</td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<?
$sql = " select a.*, b.bo_subject, c.gr_subject, c.gr_id
          $sql_common
          $sql_order
          limit $new_write_rows ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
    $tmp_write_table = $g4['write_prefix'] . $row['bo_table'];
    if ($row['wr_id'] == $row['wr_parent']) // 원글
    {
        $comment = "";
        $comment_link = "";
        $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_id]' ");
        $name = get_sideview($row2['mb_id'], cut_str($row2['wr_name'], $config['cf_cut_name']), $row2['wr_email'], $row2['wr_homepage']);
        // 당일인 경우 시간으로 표시함
        $datetime = substr($row2['wr_datetime'],0,10);
        $datetime2 = $row2['wr_datetime'];
        if ($datetime == $g4['time_ymd'])
            $datetime2 = substr($datetime2,11,5);
        else
            $datetime2 = substr($datetime2,5,5);
    }
    else // 코멘트
    {
        $comment = "[코] ";
        $comment_link = "#c_{$row[wr_id]}";
        $row2 = sql_fetch(" select * from $tmp_write_table where wr_id = '$row[wr_parent]' ");
        $row3 = sql_fetch(" select mb_id, wr_name, wr_email, wr_homepage, wr_datetime from $tmp_write_table where wr_id = '$row[wr_id]' ");
        $name = get_sideview($row3['mb_id'], cut_str($row3['wr_name'], $config['cf_cut_name']), $row3['wr_email'], $row3['wr_homepage']);
        // 당일인 경우 시간으로 표시함
        $datetime = substr($row3['wr_datetime'],0,10);
        $datetime2 = $row3['wr_datetime'];
        if ($datetime == $g4['time_ymd'])
            $datetime2 = substr($datetime2,11,5);
        else
            $datetime2 = substr($datetime2,5,5);
    }
    $list = $i%2;
    echo "
    <tr class='list$list col1 ht center'>
        <td class=small><a href='$g4[bbs_path]/new.php?gr_id=$row[gr_id]'>".cut_str($row['gr_subject'],10)."</a></td>
        <td class=small><a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]'>".cut_str($row['bo_subject'],20)."</a></td>
        <td align=left style='word-break:break-all;'>&nbsp;<a href='$g4[bbs_path]/board.php?bo_table=$row[bo_table]&wr_id=$row2[wr_id]{$comment_link}'>{$comment}".conv_subject($row2['wr_subject'], 100)."</a></td>
        <td>$name</td>
        <td>$datetime</td>
    </tr> "; 
}
if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>";
echo "<tr><td colspan='$colspan' class='line2'></td></tr>";
echo "</table>";
?>
- opencode.co.kr -


제목Page 10/28
2011-11   14733   불당
2011-10   13472   불당
2011-10   13526   불당
2011-10   13897   불당
2011-10   14655   불당
2011-10   11434   불당
2011-10   13722   불당
2011-10   13800   불당
2011-10   17594   불당
2011-10   14016   불당
2011-10   13545   불당
2011-10   13623   불당
2011-10   12621   불당
2011-10   14662   불당
2011-10   10587   불당
2011-10   12342   불당
2011-10   9938   불당
2011-10   11006   불당
2011-10   10953   불당
2011-10   18153   불당