/////////////////////////////////////////////////////////////////////////
폼에서 넘어 오는 값
검색어 : $SuyooName
연산자 : AND 또는 OR
; 검색어 복수 검색 구분자는 콤마로 (,)
/////////////////////////////////////////////////////////////////////////
$searchWord = explode(“,”,$SuyooName);
$Query = “SELECT no,OldSuyooName,SuyooCode FROM TempSuyoo WHERE “;
$wCnt = count($searchWord);
while(list($key,$value) = each($searchWord))
{
if($key > 0)
{
if($value)
{
if($key < $wCnt) $Where .= " $operator ";
}
}
if($value)
{
$Where .= ” OldSuyooName like ‘%$value%’ “;
}
}
$Query .= $Where;
/////////////////////////////////////////////////////////////////////////
위 방법으로 하면 검색어 입력시 쿼리예
1. 경상남도,하동
SELECT no,OldSuyooName,SuyooCode FROM TempSuyoo
WHERE OldSuyooName like ‘%경상남도%’ AND OldSuyooName like ‘%하동%’
2. 경상남도,
SELECT no,OldSuyooName,SuyooCode FROM TempSuyoo
WHERE OldSuyooName like ‘%경상남도%’
3. 경상남도,,하동
SELECT no,OldSuyooName,SuyooCode FROM TempSuyoo
WHERE OldSuyooName like ‘%경상남도%’ AND OldSuyooName like ‘%하동%’
이렇게 해도 실제 존재하는 검색어에 해당하는 쿼리만 생성을 합니다.
/////////////////////////////////////////////////////////////////////////