게시판 리스트 엑셀 다운로드 문의드립니다. 채택완료
안녕하세요
아래링크 팁 게시판의 내용을 참고해서
적용을 했습니다.
https://sir.kr/g5_tip/21184?sfl=wr_subject%7C%7Cwr_content&stx=%EC%97%91%EC%85%80
엑셀 다운로드 까지는 잘 되는데
엑셀 안에 게시판 여분필드 내용이 하나도 나오지 않고 있습니다. ㅠ
아무래도
&wr_id=<?= $list[$i]['wr_id'] ?>
이부분에서 값을 못받아와서 그런거 같은데..
검색을 안했을땐 전부 받고
검색했을땐 검색한 게시물만 받고싶습니다.
뭐가 잘못된건지 잘 모르겠습니다... 고수님들 도와주세요..
</p>
<p><a href="<?= $board_skin_url ?>/excel_view.php?bo_table=<?= $bo_table ?>&wr_id=<?= $list[$i]['wr_id'] ?>" class="btn_b01 btn">엑셀다운</a>
excel_view.php
</p>
<p><?php
include_once('./_common.php');
set_include_path( get_include_path().PATH_SEPARATOR."..");
include_once(G5_LIB_PATH."/xlsxwriter.class.php");
$wr_id = isset($_GET['wr_id']) ? intval($_GET['wr_id']) : 0;
$bot_table = $g5['write_prefix'].$bo_table;
$filename = "테스트신청현황.xlsx";
$filepath1 = G5_DATA_PATH.'/tmp/'.$filename;
$writer = new XLSXWriter();
$result = sql_query("select wr_id,wr_content,wr_name,wr_last,wr_1,wr_2,wr_3,wr_4,wr_5,wr_6,wr_7,wr_8,wr_9,wr_10 from {$bot_table} where wr_id = '{$wr_id}' order by wr_name");
$header = [];
$widths = [];
// $header 제목명은 모두 달라야 됨, 뒤에 여러 서식을 지정할 수 있습니다.(위 github 참조)
$header["연번"] = 'integer';
$header["이름"] = 'string';
$header["여분1"] = 'string';
$header["여분2"] = 'string';
$header["여분3"] = 'string';
$header["여분4"] = 'string';
$header["여분5"] = 'string';
$header["여분6"] = 'string';
$header["여분7"] = 'string';
$header["여분8"] = 'string';
$header["여분9"] = 'string';
$header["여분10"] = 'string';
$header["내용"] = 'string';
$header["신청일"] = 'string';
//셀너비
$widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20;$widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 20; $widths[] = 30;
$styles1 = array('font'=>'맑은 고딕','font-size'=>12,'font-style'=>'bold', 'fill'=>'#ccff999', 'halign'=>'left', 'valign'=>'center', 'border'=>'left,right,top,bottom', 'widths'=>$widths);
$styles2 = array('font'=>'맑은 고딕','font-size'=>12, 'halign'=>'left', 'valign'=>'center', 'border'=>'left,right,top,bottom','wrap_text'=>true);
$writer->writeSheetHeader('Sheet1', $header, $styles1); //제목줄 서식 포함
$contents = [];
$x = 0;
foreach ($result as $field) {
$x++;
$contents[] = $x;
$contents[] = $field['wr_name'];
$contents[] = $field['wr_1'];
$contents[] = $field['wr_2'];
$contents[] = $field['wr_3'];
$contents[] = $field['wr_4'];
$contents[] = $field['wr_5'];
$contents[] = $field['wr_6'];
$contents[] = $field['wr_7'];
$contents[] = $field['wr_8'];
$contents[] = $field['wr_9'];
$contents[] = $field['wr_10'];
$contents[] = $field['wr_content'];
$contents[] = $field['wr_last'];
$writer->writeSheetRow('Sheet1', $contents, $styles2);
$contents = [];
}
$writer->writeToFile($filepath1);
</p>
<p>//아래부분은 수정할 필요 없습니다.
$filepath = addslashes($filepath1);
$original = urlencode($filename);
if(preg_match("/msie/i", $_SERVER["HTTP_USER_AGENT"]) && preg_match("/5\.5/", $_SERVER["HTTP_USER_AGENT"])) {
header("content-type: doesn/matter");
header("content-length: ".filesize("$filepath"));
header("content-disposition: attachment; filename=\"$original\"");
header("content-transfer-encoding: binary");
} else if (preg_match("/Firefox/i", $_SERVER["HTTP_USER_AGENT"])){
header("content-type: file/unknown");
header("content-length: ".filesize("$filepath"));
header("content-disposition: attachment; filename=\"".basename($filename)."\"");
header("content-description: php generated data");
} else {
header("content-type: file/unknown");
header("content-length: ".filesize("$filepath"));
header("content-disposition: attachment; filename=\"$original\"");
header("content-description: php generated data");
}
header("pragma: no-cache");
header("expires: 0");
flush();
$fp = fopen($filepath, "rb");
if (!fpassthru($fp)) {
fclose($fp);
}
//파일 삭제
if(file_exists($filepath1)) {
@unlink($filepath1);
}</p>
<p>
답변 3개
<a href="<?= $board_skin_url ?>/excel_view.php?bo_table=<?= $bo_table ?>&wr_id=<?= $list[$i]['wr_id']?>&stx=<?=$stx?>&stx2=<?=$stx2?>&stx3=<?=$stx3?>&s_Date=<?=$s_Date?>&e_Date=<?=$e_Date?>" class="btn_b01 btn">엑셀다운</a>
wr_datetime 값은 시분초가 들어 있어 일자검색은 아래형식으로 해보세요.
left(wr_datetime,10) >= '$s_Date'";
다른것은 문제가 없는것 같은데 값은 다 받아 오나요.
답변에 대한 댓글 4개
wr_9에는 회원 아이디가 들어가는데 엑셀로 출력하면 이름이 아닌 아이디가 출력되더라구요
if (!empty($stx3)) {
// wr_9와 mb_id 비교하여 일치하면 mb_name을 가져와서 stx3로 설정
$mbNameQuery = "SELECT mb_name FROM g5_member WHERE mb_id = '$stx3'";
$mbNameResult = sql_fetch($mbNameQuery);
if ($mbNameResult) {
$stx3 = $mbNameResult['mb_name'];
} else {
// 일치하는 mb_id를 찾지 못한 경우 기존 stx3 값을 유지
}
$sql .= " AND wr_9 = '$stx3'";
}
wr_9와 mb_id 를 비교해서 해당 mb_name을 뽑으려고 이렇게 해봣는데..
여전히 아이디만 나와서요.. ㅜ
foreach ($result as $field) {
$x++;
$mbNameQuery = "SELECT mb_name FROM g5_member WHERE mb_id = '{$field['wr_9']}'";
$mbNameResult = sql_fetch($mbNameQuery);
if ($mbNameResult) {
$mb_name = $mbNameResult['mb_name'];
} else {
$mb_name = $field['wr_9'];
}
//아래 $contents[] = $field['wr_9']; 를 $contents[] = $mb_name; 으로 수정
$contents[] = $x;
댓글을 작성하려면 로그인이 필요합니다.
</strong> <span style="font-size:11pt;"><code>//링크수정 //$list[$i]['wr_id'] 는 게시판 리스트용 아이디입니다. wr_id에 값이 들어있는지 확인하세요. <a href="<?= $board_skin_url ?>/excel_view.php?bo_table=<?= $bo_table ?>&wr_id=<?= $list[$i]['wr_id']?>&stx=<?=$stx?>" class="btn_b01 btn">엑셀다운</a></code></span></pre> <pre> <span style="font-size:11pt;"><code>//excel_view.php 수정 //아래 내용 추가 및 수정해 보세요. //전부 받은경우는 &wr_id=<?= $list[$i]['wr_id']?> 는 필요없음. $stx = isset($_GET['stx']) ? trim($_GET['stx']) : '';</code></span></pre> <p><span style="font-size:11pt;"><code>if($stx == '') { //전부받을 경우</code></span></p> <pre> <span style="font-size:11pt;"><code>$result = sql_query("select wr_id,wr_content,wr_name,wr_last,wr_1,wr_2,wr_3,wr_4,wr_5,wr_6,wr_7,wr_8,wr_9,wr_10 from {$bot_table} order by wr_name");</code></span></pre> <p><span style="font-size:11pt;"><code>} else { //검색어 있는경우 wr_subject 기준</code></span></p> <pre> <span style="font-size:11pt;"><code>$result = sql_query("select wr_id,wr_content,wr_name,wr_last,wr_1,wr_2,wr_3,wr_4,wr_5,wr_6,wr_7,wr_8,wr_9,wr_10 from {$bot_table} where wr_subject like '{$stx}' order by wr_name");</code></span></pre> <p><span style="font-size:11pt;"><code>}</code></span></p> <p><strong>
답변에 대한 댓글 2개
말씀해주신대로 하니 잘됩니다!
근데 검색을 제목뿐만 아니라 이름,여분필드,날짜등까지 해버려서요..
이럴경우는 어떻게 묶어줘야 할까요? else 로 전부 경우의 수를 다 넣어줘야 할지요
$stx2 = isset($_GET['stx2']) ? trim($_GET['stx2']) : '';
$stx3 = isset($_GET['stx3']) ? trim($_GET['stx3']) : '';
$s_Date = isset($_GET['s_Date']) ? trim($_GET['s_Date']) : '';
$e_Date = isset($_GET['e_Date']) ? trim($_GET['e_Date']) : '';
// 기본 SQL 쿼리
$sql = "SELECT wr_id, wr_content, wr_name, wr_datetime, wr_1, wr_2, wr_3, wr_4, wr_5, wr_6, wr_7, wr_8, wr_9, wr_10 FROM {$bot_table} WHERE 1";
// 검색 조건이 비어있지 않을 때, 해당 조건을 추가
if (!empty($stx)) {
$sql .= " AND wr_2 = '$stx'";
}
if (!empty($stx2)) {
$sql .= " AND wr_5 = '$stx2'";
}
if (!empty($stx3)) {
$sql .= " AND wr_9 = '$stx3'";
}
if (!empty($s_Date)) {
$sql .= " AND wr_datetime >= '$s_Date'";
}
if (!empty($e_Date)) {
$sql .= " AND wr_datetime <= '$e_Date'";
}
// 최종 SQL 쿼리
$sql .= " ORDER BY wr_name";
// SQL 쿼리 실행
$result = sql_query($sql);
이렇게 해보고있는중인데 값이 안들어오네요 ㅠ
댓글을 작성하려면 로그인이 필요합니다.
$result = sql_query("select wr_id,wr_content,wr_name,wr_last,wr_1,wr_2,wr_3,wr_4,wr_5,wr_6,wr_7,wr_8,wr_9,wr_10 from {$bot_table} where wr_id = '{$wr_id}' order by wr_name");
여기 쿼리를 보면
해당 데이터의 기준점이 되는
{$bot_table} // bo_table 보드ID 로 추정
{$wr_id} // wr_id 글번호
이렇게 2가지 데이터가 있어야 합니다.
리스트에서 실행할경우 bo_table 은 GET 으로 받을 수 있고
뷰페이지에서 실행할경우 bo_table 및 해당 게시물 wr_id 도 받을수 있습니다.
각각 응용하셔서 처리하시면됩니다.
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인
정말 감사합니다!!!ㅠ_ㅠ