채택완료

select sql쿼리된 값이 없는 것을 조건으로 조건식을 만들 때 어떻게 하나요?

2023-02-01 (수) 17:13:56 3,057

안녕하세요

A필드 B필드 두개중에서 먼저 

A필드를 쿼리해서 값이 없으면 

B필드를 쿼리하는 조건식 좀 알려주세요.

 $sql = "select img_source  from g5_board_file where bo_table='{$bo_table}' and wr_id='{$wr_id}' ";

 $result = sql_query($sql);

 $arr = mysql_fetch_array($result);

if ($arr[0] == "") {

// 값이 없을때

} else {

//값이 있을 때

}

이렇게 하는게 맞나요?

안되서

|

답변 2개 / 댓글 1개

채택된 답변
+20 포인트
Copy
$sql = "select A필드, B필드 from g5_board_file where bo_table='{$bo_table}' and wr_id='{$wr_id}' ";

 $result = sql_fetch($sql);

 

$fieldval = '';

if ($fieldval == '' && empty($result['A필드']) === false) {

    $fieldval = $result['A필드'];

}

if ($fieldval == '' && empty($result['B필드']) === false) {

    $fieldval = $result['B필드'];

}

답변에 대한 댓글 1개

2023-02-01 (수) 17:56:49
감사합니다.꾸벅
2023-02-02 (목) 06:06:48

select if( img_source_a>' ', img_source_a, img_source_b) AS img_source from g5_board_file where bo_table='{$bo_table}' and wr_id='{$wr_id}' ";

답변을 작성하려면 로그인이 필요합니다.