자바스크립트 체크박스 배열 값 DB저장 채택완료
Copy
function ajax_del(){
if (!confirm(`정말로 삭제하시겠습니까?`)) {
//취소(아니오) 버튼 클릭 시 이벤트
} else {
// 확인(예) 버튼 클릭 시 이벤트
var chk = [];
$("input[name='chk[]']:checked").each(function(i){
chk.push($(this).val());
});
let data = {"chk" : chk};
console.log(data);
$.ajax({
url:"/admin/ajax_delete.php",
type:'POST',
data: data,
success:function(data){
alert("삭제가 완료되었습니다.");
location.reload(true);
},
error:function(jqXHR, textStatus, errorThrown){
alert("에러 발생~~ \n" + textStatus + " : " + errorThrown);
self.close();
}
});
}
}
스크립트로 체크된 배열값을 보내긴 하였습니다.
ajax_delete.php
Copy
배열값은 no이고 no에 해당된 데이터정보들을 삭제는 가능합니다. 하지만 sw_pin_box테이블에서는 삭제되지만 그 정보들을 그대로 sw_pin_box_del테이블에 insert를 해야하는데 이름이랑 등등을 배열로 다시 해야하는데 어려워서 해결하지못하고있습니다ㅠㅠㅠ 방법좀알려주세요..
답변 1개
채택된 답변
+20 포인트
Actonsoft
2년 전
Copy
if($subqry) {
$find_no = sql_fetch("SELECT * FROM sw_pin_box WHERE no IN ($subqry)");
if ($find_no) {
sql_query("INSERT INTO sw_pin_box_del (no, it_id, it_name, it_price, pin, status, datetime)
VALUES ('{$find_no['no']}', '{$find_no['it_id']}', '{$find_no['it_name']}', '{$find_no['it_price']}', '{$find_no['pin']}', 'N', NOW())");
}
sql_query("DELETE from sw_pin_box where no in ($subqry)");
}
dud 님 다시 뵙네요, 해당 코드로 해보시겠나요?
로그인 후 평가할 수 있습니다
답변에 대한 댓글 5개
�
2년 전
[code]
if($subqry) {
$cnt = count($chk_arr);
for($i=0; $i<$cnt; $i++) {
$find_no = sql_fetch("SELECT * FROM sw_pin_box WHERE no = $chk_arr[$i]");
if ($find_no) {
sql_query("INSERT INTO sw_pin_box_del (no, it_id, it_name, it_price, pin, status, datetime)
VALUES ('{$find_no['no']}', '{$find_no['it_id']}', '{$find_no['it_name']}', '{$find_no['it_price']}', '{$find_no['pin']}', 'N', NOW())");
}
}
sql_query("DELETE from sw_pin_box where no in ($subqry)");
}
[/code]
if($subqry) {
$cnt = count($chk_arr);
for($i=0; $i<$cnt; $i++) {
$find_no = sql_fetch("SELECT * FROM sw_pin_box WHERE no = $chk_arr[$i]");
if ($find_no) {
sql_query("INSERT INTO sw_pin_box_del (no, it_id, it_name, it_price, pin, status, datetime)
VALUES ('{$find_no['no']}', '{$find_no['it_id']}', '{$find_no['it_name']}', '{$find_no['it_price']}', '{$find_no['pin']}', 'N', NOW())");
}
}
sql_query("DELETE from sw_pin_box where no in ($subqry)");
}
[/code]
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인