이미지파일 덮어씌우기
본문
그누보드 테이블에 g5_board_file이 있습니다
수정시 g5_board_file_copy 라는 테이블에 글을 수정 시 이미지 수정이되면
여기에 먼저 저장이 됩니다.
그 후 이미지가 확인이되면 copy테이블에서 -> 기존 g5_board_file로 bf_no의 수에 맞게 값이 있으면 업데이트 시키고 없으면 insert를 시켜주려고 합니다.
$sql3 = " select * from g5_board_file_copy where wr_id = '$wr_id' and bo_table= '$bo_table' ";
$bk = sql_fetch($sql3); 의 쿼리를 날린후
$total_cnt2 는 copy의 조건에 맞는 개수입니다.
for($i=0;$i<$total_cnt2;$i++){
if($total_cnt == 0){
$trans_bf = " insert into g5_board_file
set bo_table = '{$bo_table}',
wr_id = '{$wr_id}',
bf_no = 0,
bf_source = '{$bf[$i]['bf_source']}',
bf_file = '{$bf[$i]['bf_file']}',
bf_content = '{$bf[$i]['bf_content']}',
bf_fileurl = '{$bf[$i]['bf_fileurl']}',
bf_thumburl = '{$bf[$i]['bf_thumburl']}',
bf_storage = '{$bf[$i]['bf_storage']}',
bf_download = 0,
bf_filesize = '{$bf[$i]['bf_filesize']}',
bf_width = '{$bf[$i]['bf_width']}',
bf_height = '{$bf[$i]['bf_height']}',
bf_type = '{$bf[$i]['bf_type']}',
bf_datetime = '{$bf[$i]['bf_datetime']}'
";
sql_query($trans_bf);
}else{
$trans_bf = " update g5_board_file
set bf_source = '{$bf[$i]['bf_source']}',
bf_file = '{$bf[$i]['bf_file']}',
bf_content = '{$bf[$i]['bf_content']}',
bf_fileurl = '{$bf[$i]['bf_fileurl']}',
bf_thumburl = '{$bf[$i]['bf_thumburl']}',
bf_storage = '{$bf[$i]['bf_storage']}',
bf_filesize = '{$bf[$i]['bf_filesize']}',
bf_width = '{$bf[$i]['bf_width']}',
bf_height = '{$bf[$i]['bf_height']}',
bf_type = '{$bf[$i]['bf_type']}',
bf_datetime = '{$bf[$i]['bf_datetime']}'
where bo_table = '{$bo_table}'
and wr_id = '{$wr_id}'
";
sql_query($trans_bf);
}
insert도 안되고 update 도 안되서...
혹시 이해가가신다면 뭐가 잘못된건지 짚어주시면 감사하겠습니다.
답변 1
$sql3 = "SELECT * FROM g5_board_file_copy WHERE wr_id = '$wr_id' AND bo_table = '$bo_table'";
$bk = sql_fetch($sql3);
$total_cnt2 = count($bk); // copy의 조건에 맞는 개수
for ($i = 0; $i < $total_cnt2; $i++) {
if ($total_cnt == 0) {
$trans_bf = "INSERT INTO g5_board_file
SET bo_table = '{$bo_table}',
wr_id = '{$wr_id}',
bf_no = 0,
bf_source = '{$bk[$i]['bf_source']}',
bf_file = '{$bk[$i]['bf_file']}',
bf_content = '{$bk[$i]['bf_content']}',
bf_fileurl = '{$bk[$i]['bf_fileurl']}',
bf_thumburl = '{$bk[$i]['bf_thumburl']}',
bf_storage = '{$bk[$i]['bf_storage']}',
bf_download = 0,
bf_filesize = '{$bk[$i]['bf_filesize']}',
bf_width = '{$bk[$i]['bf_width']}',
bf_height = '{$bk[$i]['bf_height']}',
bf_type = '{$bk[$i]['bf_type']}',
bf_datetime = '{$bk[$i]['bf_datetime']}'";
sql_query($trans_bf);
} else {
$trans_bf = "UPDATE g5_board_file
SET bf_source = '{$bk[$i]['bf_source']}',
bf_file = '{$bk[$i]['bf_file']}',
bf_content = '{$bk[$i]['bf_content']}',
bf_fileurl = '{$bk[$i]['bf_fileurl']}',
bf_thumburl = '{$bk[$i]['bf_thumburl']}',
bf_storage = '{$bk[$i]['bf_storage']}',
bf_filesize = '{$bk[$i]['bf_filesize']}',
bf_width = '{$bk[$i]['bf_width']}',
bf_height = '{$bk[$i]['bf_height']}',
bf_type = '{$bk[$i]['bf_type']}',
bf_datetime = '{$bk[$i]['bf_datetime']}'
WHERE bo_table = '{$bo_table}'
AND wr_id = '{$wr_id}'";
sql_query($trans_bf);
}
}