엑셀 코멘트 다운로드 질문드립니다.
본문
// 원글 + 코멘트 다운로드
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} "));
$sql="select * from {$excel_down} {$search} order by wr_datetime desc";
$qry=sql_query($sql);
위 코드로 게시글을 엑셀로 받고 있습니다.
혹시 코멘트만 받도록 수정하려면 어떻게 해야할까요?
답변 3
<?php
include_once "_common.php";
$bo_table = $_REQUEST['bo_table'];
$excel_down = $g5['write_prefix'] . $bo_table; //엑셀 다운로드 테이블
$wr_id = $_REQUEST['wr_id'];
$hp_filename = $bo_table."_".date('Y_md h_m');
$g5['title'] = "엑셀 문서 다운로드";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
header( "Content-Description: PHP4 Generated Data" );
//이 부분이 추가
$search = " where wr_is_comment = 1 and wr_parent = '{$wr_id}' ";
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} {$search} "));
$sql="select * from {$excel_down} {$search} order by wr_datetime desc";
$qry=sql_query($sql);
$number=$temp[0];
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.txt {
mso-style-parent:style0;
mso-number-format:"\@";
border:.5pt solid windowtext;
}
</style>
</head>
<body>
<table>
<tr>
<td class='txt'>이름</td>
<td class='txt'>추가1</td>
<td class='txt'>추가2</td>
<td class='txt'>추가3</td>
<td class='txt'>추가4</td>
<td class='txt'>추가5</td>
<td class='txt'>추가6</td>
<td class='txt'>추가7</td>
<td class='txt'>추가8</td>
<td class='txt'>추가9</td>
<td class='txt'>내용</td>
<td class='txt'>작성일</td>
</tr>
<?php
while($row=sql_fetch_array($qry)) {
echo "
<tr>
<td class='txt'>{$row['wr_name']}</td>
<td class='txt'>{$row['wr_1']}</td>
<td class='txt'>{$row['wr_2']}</td>
<td class='txt'>{$row['wr_3']}</td>
<td class='txt'>{$row['wr_4']}</td>
<td class='txt'>{$row['wr_5']}</td>
<td class='txt'>{$row['wr_6']}</td>
<td class='txt'>{$row['wr_7']}</td>
<td class='txt'>{$row['wr_8']}</td>
<td class='txt'>{$row['wr_9']}</td>
<td class='txt'>".get_text(strip_tags($row['wr_content']))."</td>
<td class='txt'>{$row['wr_datetime']}</td>
</tr>
";
$number--;
}
?>
</table>
</body>
</html>
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} where wr_is_comment = 1 "));
전체 댓글만 다운로드 하려면 이렇게 하면 됩니다.
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} where wr_is_comment = 1 and wr_id = '{$wr_id}' "));
해당 게시물의 댓글만 다운 받으려면 이렇게 하면 됩니다.
$bo_table = $_REQUEST['bo_table'];
$excel_down = $g5['write_prefix'] . $bo_table; //엑셀 다운로드 테이블
$wr_id = $_REQUEST['wr_id'];
$hp_filename = $bo_table."_".date('Y_md h_m');
$g5['title'] = "엑셀 문서 다운로드";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename={$hp_filename}.xls" );
header( "Content-Description: PHP4 Generated Data" );
$date1 = $_POST['date1']." 00:00:00";
$date2 = $_POST['date2']." 23:59:59";
//아래 부분은 날짜 기간 으로 검색 가능
$search = " where 1 ";
if ($_POST['date1'] && !$_POST['date2']) {
$search = " and wr_datetime > '{$date1}' ";
} elseif (!$_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime < '{$date2}' ";
} elseif ($_POST['date1'] && $_POST['date2']) {
$search = " and wr_datetime > '{$date1}' && wr_datetime < '{$date2}' ";
}
//이 부분이 추가
$search .= " and wr_is_comment = 1 and wr_id = '{$wr_id}' ") ";
$temp=sql_fetch_array(sql_query("select count(*) from {$excel_down} {$search} "));
$sql="select * from {$excel_down} {$search} order by wr_datetime desc";
$qry=sql_query($sql);
$number=$temp[0];