<?
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header("Content-Disposition: attachment; filename=file.xls");
header("Content-Description: PHP5 Generated Data");
include "_common.php";
if($_POST['chk']) {
for ($i=0; $i<count($_POST['chk']); $i++) {
$k = $_POST['chk'][$i];
$od_id[] = $_POST['od_id'][$k];
}
$od = implode(", ", $od_id);
$where = "WHERE od_id IN($od)";
}
?>
<table border="1">
<tr>
<th>주문번호</th>
<th>이름</th>
<th>전화번호</th>
</tr>
<?
$que = sql_query("SELECT * FROM {$g5['g5_shop_order_table']} $where order by od_id");
while($row = sql_fetch_array($que)) {
?>
<tr>
<td style='mso-number-format:\@;'><?=$row['od_id']?></td>
<td><?=$row['od_b_name']?></td>
<td style='mso-number-format:\@;'><?=$row['od_tel']?></td>
</tr>
<?
}
?>
</table>
선택된 것만 엑셀 다운 받는 소스인데 페이지 전체의 정보가 다운됩니다.
이유를 모르겠습니다. 정말 몰라요. 죄송합니다. 질문해서 죄송합니다.
제발 알려주십시오.
답변 2개 / 댓글 21개
한번 답찍어보기를 해본다면..
$where = "WHERE od_id IN($od)";
->
$where = "WHERE od_id IN( {$od} )";
해보면 어떨까 싶습니다.
답이 아니라면..
-------------------
상단의 excel 관련 헤더 3 Line 을 임시 주석처리하여,
엑셀파일이 아닌 화면으로 먼저 디버깅하여,
문제를 수정한 뒤, 주석을 해제하는 것을 추천합니다.
선택된 것만이 아닌, 전체가 나오는 것은 쿼리문에 문제가 있을 가능성이 큽니다.
$where = "WHERE od_id IN($od)"; 문 아래에
echo $where;
통해 where 문이 제대로 작성되었는지,
echo $od;
print_r2($od_id);
등을 통해 차근차근 값이 제대로 들어있는지 확인해보는 것이 좋을 듯 합니다.
답변에 대한 댓글 18개
전체 페이지 내용이 나오는 것은, echo 문 이후에도 계속 실행이 되기 때문인 것으로 잘못 파악한 것일 수 있습니다.
echo $where; exit; 를 하면.. 좀 더 명확히 $where 문을 살펴볼 수 있습니다.
그렇다면 여기 페이지는 문제가 없고..
엑셀버튼이 있는 페이지에서 처리가 제대로 되지 않았을 가능성이 높습니다.
(체크한 것의 번호만 넘어와야 하는데, 그렇지 않은 것으로 보입니다.)
를 하여, 선택된 값만 나온다면 제대로 나오는 것이고,
선택하지 않은 값들 까지 나온다면.. 엑셀버튼이 있는 전페이지의 문제일 가능성이 높습니다.
implode() 는 배열의 각 값들을 해당 기호로 하나의 단일 스트링으로 만들어주는 함수입니다.
이 구문에 별 문제는 없어 보이는데..
혹시나 한다면.. for 문 전에
$od_id = array();
로 배열값을 초기화 시켜주거나 ..
$od_id 가 아닌 다른 이름을 사용해보면 어떨까 합니다.
$arr_od = array();
for ($i=0; $i<count($_POST['chk']); $i++) {
$k = $_POST['chk'][$i];
$arr_od[] = $_POST['od_id'][$k];
}
$od = implode(", ", $arr_od);
echo $od; exit;
다른 이름의 변수로 해보셨으면 합니다.
$arr_od = array();
for ($i=0; $i<count($_POST['chk']); $i++) {
$k = $_POST['chk'][$i];
$arr_od[] = $_POST['od_id'][$k];
}
$od = implode(", ", $arr_od);
넘기기전 input
<input type="checkbox" class="chk" name="chk[]" value="<?=$row['od_id'] ?>" title="선택">
<?
header('Content-Type: application/vnd.ms-excel; charset=utf-8');
header("Content-Disposition: attachment; filename=file.xls");
header("Content-Description: PHP5 Generated Data");
include "_common.php";
$check = $_POST['chk'];
$od = implode(", '", $check);
$where = "WHERE od_id IN('{$od}')";
?>
<table border="1">
<tr>
<th>주문번호</th>
<th>이름</th>
<th>전화번호</th>
</tr>
<?
$que = sql_query("SELECT * FROM {$g5['g5_shop_order_table']} $where order by od_id");
while($row = sql_fetch_array($que)) {
?>
<tr>
<td style='mso-number-format:\@;'><?=$row['od_id']?></td>
<td><?=$row['od_b_name']?></td>
<td style='mso-number-format:\@;'><?=$row['od_tel']?></td>
</tr>
<?
}
?>
</table>
답변에 대한 댓글 3개
<input type="checkbox" name="chk[]" value="<?php echo $i ?>" id="chk_<?php echo $i ?>">
이게 기존거인데 만약 위에 주신것처럼 바꿔도 기존 기능인 수정이나 삭제에 문제는 없나요?
답변을 작성하려면 로그인이 필요합니다.