mysql 질문입니다.
본문
mysql.. 안만지면 헷갈려요 ㅠㅠ
photo_list_table 의 검색된 결과값이 없다면
36번째 줄에 있는 insert_sql_photo_info 문을 실행시키고 싶은데 어찌 해야 할까요;;;
답변 좀 부탁드립니다.
<?php
include_once('./_common.php');
include_once(G5_LIB_PATH.'/common.lib.php');
include_once(G5_LIB_PATH.'/build_thumbnail.lib.php');
$BUILD_ID = $_POST['BUILD_ID'];
$BUILD_SEQ = $_POST['BUILD_SEQ'];
$COMP_CD = $_POST['COMP_CD'];
$PHOTO_BOARD_TABLE = " SELECT * FROM {$TB['BUILD_SALE_MST_DTL_PHOTO']} WHERE COMP_CD = '$COMP_CD' AND BUILD_ID = '$BUILD_ID' AND BUILD_SEQ = '$BUILD_SEQ' ";
$PHOTO_BOARD_ROW = sql_query($PHOTO_BOARD_TABLE);
$PHOTO_BOARD=sql_fetch_array($PHOTO_BOARD_ROW);
if($PHOTO_BOARD['BUILD_SEQ']) {
// $PHOTO_ID = $PHOTO_BOARD['BUILD_SEQ'];
$PHOTO_LIST_TABLE = " SELECT * FROM {$TB['BUILD_SALE_MST_DTL_PHOTO_FILE']} WHERE COMP_CD = '$COMP_CD' AND BUILD_ID = '$BUILD_ID' AND BUILD_SEQ = '$BUILD_SEQ' and PHOTO_TYPE between '1' and '3' ";
$PHOTO_LIST_ROW = sql_query($PHOTO_LIST_TABLE);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ret = array();
for($i=1; $row=sql_fetch_array($PHOTO_LIST_ROW); $i++)
{
$details = array();
$details['COMP_CD']=$row['COMP_CD'];
$details['BUILD_ID']=$row['BUILD_ID'];
$details['BUILD_SEQ']=$row['BUILD_SEQ'];
$details['PHOTO_NO']=$row['PHOTO_NO'];
$details['IN_OR_OUT']=$row['IN_OR_OUT'];
$details['PHOTO_NAME']=$row['PHOTO_NAME'];
$details['PHOTO_FILE']=$row['PHOTO_FILE'];
$details['PHOTO_FILESIZE']=$row['PHOTO_FILESIZE'];
$details['width']=$PHOTO_BOARD['PHOTO_IMAGE_WIDTH'];
$details['height']=$PHOTO_BOARD['PHOTO_IMAGE_HEIGHT'];
$ret[] = $details;
}
// $insert_sql_photo_info = " UPDATE {$TB['BUILD_SALE_MST_DTL_PHOTO']} SET IS_PICTURE = 'N' WHERE COMP_CD = '2000' and BUILD_ID = '1000' and BUILD_SEQ = '12' ";
// $insert_photo_info = sql_query($insert_sql_photo_info);
echo json_encode($ret);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
?>
답변 2
<?php
include_once('./_common.php');
include_once(G5_LIB_PATH.'/common.lib.php');
include_once(G5_LIB_PATH.'/build_thumbnail.lib.php');
$BUILD_ID = $_POST['BUILD_ID'];
$BUILD_SEQ = $_POST['BUILD_SEQ'];
$COMP_CD = $_POST['COMP_CD'];
$PHOTO_BOARD_TABLE = " SELECT * FROM {$TB['BUILD_SALE_MST_DTL_PHOTO']} WHERE COMP_CD = '$COMP_CD' AND BUILD_ID = '$BUILD_ID' AND BUILD_SEQ = '$BUILD_SEQ' ";
$PHOTO_BOARD_ROW = sql_query($PHOTO_BOARD_TABLE);
$PHOTO_BOARD=sql_fetch_array($PHOTO_BOARD_ROW);
if($PHOTO_BOARD['BUILD_SEQ']) {
//여기에 추가를 합니다.
$PHOTO_LIST_TABLE_CNT = " SELECT count(*) cnt FROM {$TB['BUILD_SALE_MST_DTL_PHOTO_FILE']} WHERE COMP_CD = '$COMP_CD' AND BUILD_ID = '$BUILD_ID' AND BUILD_SEQ = '$BUILD_SEQ' and PHOTO_TYPE between '1' and '3' ";
$photocnt = sql_fetch($PHOTO_LIST_TABLE_CNT);
if ($photocnt[cnt] > 0) { //Row가 존재할때 뭔가 수행
// $PHOTO_ID = $PHOTO_BOARD['BUILD_SEQ'];
$PHOTO_LIST_TABLE = " SELECT * FROM {$TB['BUILD_SALE_MST_DTL_PHOTO_FILE']} WHERE COMP_CD = '$COMP_CD' AND BUILD_ID = '$BUILD_ID' AND BUILD_SEQ = '$BUILD_SEQ' and PHOTO_TYPE between '1' and '3' ";
$PHOTO_LIST_ROW = sql_query($PHOTO_LIST_TABLE);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
$ret = array();
for($i=1; $row=sql_fetch_array($PHOTO_LIST_ROW); $i++)
{
$details = array();
$details['COMP_CD']=$row['COMP_CD'];
$details['BUILD_ID']=$row['BUILD_ID'];
$details['BUILD_SEQ']=$row['BUILD_SEQ'];
$details['PHOTO_NO']=$row['PHOTO_NO'];
$details['IN_OR_OUT']=$row['IN_OR_OUT'];
$details['PHOTO_NAME']=$row['PHOTO_NAME'];
$details['PHOTO_FILE']=$row['PHOTO_FILE'];
$details['PHOTO_FILESIZE']=$row['PHOTO_FILESIZE'];
$details['width']=$PHOTO_BOARD['PHOTO_IMAGE_WIDTH'];
$details['height']=$PHOTO_BOARD['PHOTO_IMAGE_HEIGHT'];
$ret[] = $details;
}
} else { //없으면 하고싶던 업데이트문 수행
$insert_sql_photo_info = " UPDATE {$TB['BUILD_SALE_MST_DTL_PHOTO']} SET IS_PICTURE = 'N' WHERE COMP_CD = '2000' and BUILD_ID = '1000' and BUILD_SEQ = '12' ";
$insert_photo_info = sql_query($insert_sql_photo_info);
}
echo json_encode($ret);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
?>
와 같이 변경해보세요
!-->if(!$ret[0]){
$insert_~~~
}
그리고 10, 11행은 그누보드에서는 아래처럼 하면 됩니다
$PHOTO_BOARD=sql_fetch($PHOTO_BOARD_TABLE);
답변을 작성하시기 전에 로그인 해주세요.