latest.php 부분 질문드립니다 ㅠ

latest.php 부분 질문드립니다 ㅠ

QA

latest.php 부분 질문드립니다 ㅠ

답변 1

본문

 

global $g5;
    list($bo_table, $category) = explode("|", $bo_table);

 

if($category) $where = " AND wr_1 = '".$category."' ";
if($category) {
    $cat = explode(",", $category);
    $where = " AND ca_name IN('".implode("', '", $cat)."') ";
}

 

이 부분인데, if문을 두개쓰면 인식이 안되는거 같아 여쭤보려합니다. 한개의 문장으로 모두 호용되게 가능할 수 있을까요?

이 질문에 댓글 쓰기 :

답변 1

global $g5;
list($bo_table, $category) = explode("|", $bo_table);

 

if (strstr($category, ',')) {
  $cat = explode(",", $category);
  $where = " AND ca_name IN('".implode("', '", $cat)."') ";
} else {
  $where = " AND wr_1 = '".$category."' ";
}

그렇지는 않습니다.

두개 다 참일 경우는 다음과 같이 하면 됩니다.

if ($category) {
  $where = " AND wr_1 = '".$category."' ";

  $cat = explode(",", $category);
  $where = $where . " AND ca_name IN('".implode("', '", $cat)."') ";
}

※ php에서 문자열 결합 연산자는 . 입니다.

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 672
© SIRSOFT
현재 페이지 제일 처음으로