sql select 할때 배열값은 어떻게 처리해야하나요?
본문
select 쿼리 던질때
$a[0] = "111";
$a[1] = "222";
$a[2] = "333";
$a[3] = "444";
$a[4] = "555";
$a[5] = "666";
$sql = "select * from g5_write_table where wr_id = $a";
이게 맞는 문법인가요?
검색할게 배열이라면 어떻게 처리하는것이 올바른 방법인지 궁금합니다.
!-->답변 2
$sql = "select * from g5_write_table where wr_id in (". implode(',', $a) . ") ";
아 배열값이 숫자면 저렇게 해도 상관없는데 문자열이면 따옴표 처리 안되서 오류 나겠네요.
$sql = "select * from g5_write_table where wr_id in ('". implode("\',\'", $a) . "') ";
이렇게 하면 문자열도 처리가능
답변을 작성하시기 전에 로그인 해주세요.