부탁드립니다 제발
본문
<?
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
한번 답찍어보기를 해본다면..
$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);
등을 통해 차근차근 값이 제대로 들어있는지 확인해보는 것이 좋을 듯 합니다.
넘기기전 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>