<./>.dev./hood

웹 페이지에서 보여질 컨텐츠를 엑셀 파일로 만들어 다운로드 해주는 기능이다.

나는 이 것을 영카트에서 구현해 특정 회원에 한해서만 다운로드 받을 수 있게 해두었다.

보편적으로 알려진 웹 페이지 강제 엘셀 다운로드 기능과 유사 하며, 나는 쿼리문과 동시에 세션문을 추가 해서 보여주었다.

내가 작성 한 영카트를 위한 엑셀 파일 다운로드 기능을 기준으로 설명 하자면,

include_once('./_common.php');


제일 중요 한 라이브러리 커먼파일을 불러 올 수 있도록 인클루드 해준다.

header( "Content-type: application/vnd.ms-excel" );   
header( "Content-type: application/vnd.ms-excel; charset=utf-8" );
header( "Content-Disposition: attachment; filename = product_list_all.xls" );
header( "Content-Description: PHP5 Generated Data" );


위와 같이 헤더문을 삽입해서 강제로 엑셀 파일임을 웹 페이지가 인식 할 수 있도록 해준뒤

@session_save_path($DOCUMENT_ROOT."/data/session");
@session_start();
echo $_SESSIO["ss_mb_id"];


회원별 다운로드 기능의 핵심인 세션값 인증을 위한 구문을 작성 해준다.

이후 쿼리문은 사실 자신의 기호대로 작성 해주면 되겠는데,

나의 경우는 워낙 방해 한 양의 내용을 가져와야 했기 때문에 (사실 기억도 잘 나지 않고)

하나의 변수를 만들어서 해당 내용을 인자로 만들어 묶어서 쿼리문으로 작성 해주었다.

$a = "a.it_id, a.it_name, a.ca_id, a.ca_id2, a.ca_id3, a.ca_name, a.ca_name2, a.ca_name3,  a.it_name, a.it_dis, a.it_price, a.it_explan, a.it_img1, a.it_option_subject, a.it_maker, a.it_origin, a.it_soldout, a.it_soldout, a.it_time";
$b = "b.io_id";
$c = "c.ca_id, c.ca_name, c.ca_order";

$sql = "select $a, $b, $c from g5_shop_item a left outer join g5_shop_item_option b on (a.it_id = b.it_id)
left outer join g5_shop_category c on (a.ca_id = c.ca_id)";
$sql .= "and (c.ca_id) like a.ca_id where length(a.ca_id) = 2";


이렇게 작성 한 뒤

if($fr_date && $to_date){
    $sql .= " and a.it_time between '$fr_date' and '$to_date' ";
}
$sql .= " order by a.it_id desc";
$result = sql_query($sql);

$sql2 = "select * from g5_member";
$result2 = sql_query($sql2);
$row2 = sql_fetch_array($result2);


위와 같이 조건문을 걸어 주었다.

while($row = sql_fetch_array($result)) {
echo $row[ca_name];
}


이렇게 while 루프를 돌려주는 것과 for 문을 이용 한 루프를 돌려주는 2가지 방법이 있지만 (그누보드 내부 sql_fetch_array 함수 테스트를 해본 것)

(while 문을 이용 해 cafe24 의 메모리 테스트를 해야 했기 때문에) 평소에는 while 루프를 이용하도록 하자.

for ($i=0; $row=sql_fetch_array($result); $i++) {
echo $row[ca_name];
}


정리하자면 총합 코딩 내용은 아래와 같다.

= '2014-08-08') order by a.it_id";
*/

if($fr_date && $to_date){
    $sql .= " and a.it_time between '$fr_date' and '$to_date' ";
}
$sql .= " order by a.it_id desc";
$result = sql_query($sql);

$sql2 = "select * from g5_member";
$result2 = sql_query($sql2);
$row2 = sql_fetch_array($result2);

?>

()\[\]\{\}]/i", "", $row['it_explan']);
	$address_data = "http://영카트설치 url/data/";
?>

대분류 중분류 소분류 상품번호 상품명 옵션 할인여부 B2B공급가 B2B할인공급가(VAT미포함가) B2B할인공급가(VAT포함가) 상품상세페이지 상품이미지(600*600) 제조사 원산지 품절
할인됨 = 1) { ?> 할인안됨 품절