테스트 사이트 - 개발 중인 베타 버전입니다

상품리스트 엑셀 다운로드 csv

· 6년 전 · 6068 · 15
/adm/shop_admin/itemlist.php 소스추가

<a href="#" class='btn_excel' style="background:green;color:#fff; padding:5px 10px; border-radius:5px;">엑셀 다운로드</a>

<script>
$('body').on('click', '.btn_excel', function(event) {
event.preventDefault();
var f = $('#fitemlistupdate')[0];
f.action = './itemlist_excel.php';
f.submit();
f.action = '';
return false;
});
</script>

/adm/shop_admin/itemlist_excel.php 파일추가

<?php
include_once('./_common.php');

auth_check($auth[$sub_menu], 'r');

$referer = parse_url ( $_SERVER['HTTP_REFERER'] ) ;
parse_str( $referer['query'], $output);
foreach ($output as $key => $value) {
${$key} = $value;
}

$sql_common = " from {$g5['g5_shop_item_table']} a ,
{$g5['g5_shop_category_table']} b
where (a.ca_id = b.ca_id";
if ($is_admin != 'super')
$sql_common .= " and b.ca_mb_id = '{$member['mb_id']}'";
$sql_common .= ") ";
$sql_common .= $sql_search;

$sql = " SELECT * FROM g5_shop_item";

$result = sql_query($sql);

/* ================================= */
$type = 'csv'; // comma-separated values, text 코마 구분 값 포맷의 파일
/* ================================= */

$file_alias ="itemlist_".date('Ymd').".{$type}";

header("Content-Type: application/vnd.ms-excel; charset=utf-8");
Header('Content-Disposition: attachment; filename=' . $file_alias);
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
Header('Pragma: no-cache');
Header('Expires: 0');

/* ================================= */


$filedName = array(
"분류",
"상품코드",
"상품명",
"기본설명"
);

$prtPattern = "";
foreach($filedName as $val ) {
$prtPattern .= ',"%s"';
}
$prtPattern = substr($prtPattern, 1)."\r\n";

echo "\xEF\xBB\xBF";
vprintf($prtPattern, $filedName );

$filedValues = array(
preg_replace('/[\"]/', '""', $row['ca_id'])
,preg_replace('/[\"]/', '""', $row['it_id'])
,preg_replace('/[\"]/', '""', $row['it_name'])
,preg_replace('/[\"]/', '""', $row['it_basic'])
);
vprintf($prtPattern, $filedValues );
?>

개발한것 제외하느라 정상작동할진 모르겠네요 필요하신 분 쓰세용
팁자료실에 없어서 만드느라 힘들었네요 ㅠㅠ

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

댓글 15개

데이터 값 안나오는분들

$result = sql_query($sql);
밑에
$row = sql_fetch($sql);
추가해주세요
감사합니다.
감사합니다!
감사합니다
감사합니다^^

게시글 목록

번호 제목
852
842
838
835
829
826
820
816
811
806
784
781
778
773
771
768
766
754
749
740
737
723
714
704
698
697
696
689
688
687