나는 php를 사용하여 mysql 데이터베이스에서 검색을 수행하는 다른 방법으로 6 개의 다른 검색 필터를 지정해야합니다. 나는 그것에 대해 어떻게 가는지 혼란 스럽다.PHP에서 필터를 사용하여 검색을 수행하려면 어떻게합니까?
나는 웹 사이트를 운영하고있어 6 가지 검색 필터를 사용하여 매우 큰 검색을 수행해야합니다.
이 복잡한 논리로 많은 양의 코드를 작성한 것은 이번이 처음이기 때문에 나에게 복잡해 보입니다.
<input type='text' name='searchterm' />
<select name='ind' class='custom-select'>
<option value='0'> Select Industry</option>
<option value='1'> Real Estate </option>
<option value='2'> Hospitality/Hotel/Tourism/Travel & Aviation </option>
<option value='3'> Financial Services/Banking </option>
</select>
<select name='spec' class='custom-select'>
<option value='0'> Select Specialization</option>
<option value='1'> Accounting/Banking & Finance/Insurance </option>
<option value='2'> Administration/Management/Executive </option>
<option value='3'> Architecture/Construction/Civil </option>
</select>
<select name='loc' class='custom-select'>
<option value='0'> Select Location</option>
<option value='1'> Lagos </option>
</select>
전체 HTML 코드가 여기에 있습니다 : :
이
는 HTML 코드입니다 http://jsbin.com/otibel/1/이 6 개 개의 선택 상자가 있으며, 각각 검색 필터입니다.
사용자는 한 번에 하나의 선택 상자를 선택하고 한 번에 두 개 또는 세 개의 검색 필터를 검색하거나 선택하는 등의 작업을 수행 할 수 있습니다.
필자는 검색 필터를 6 번만 관리했지만 사용자가 단 하나의 검색 필터 만 선택하면이 코드가 사용됩니다.
function performSearchWithFilter(){
if (($_GET['ind'] > 0) && (isset($_GET['ind'])) && ($_GET['spec'] <= 0) && ($_GET['loc'] <= 0) && ($_GET['workexp'] <= 0) && ($_GET['type'] <= 0) && ($_GET['qualfctn'] <= 0)){
//it will carry out the search, when just the ind select box has been selected
} else if (($_GET['ind'] <= 0) && ($_GET['spec'] > 0) && isset($_GET['spec']) && ($_GET['loc'] <= 0) && ($_GET['workexp'] <= 0) && ($_GET['type'] <= 0) && ($_GET['qualfctn'] <= 0)) {
//it will carry out the search, when just the spec select box has been selected
} else if (($_GET['ind'] <= 0) && ($_GET['spec'] <= 0) && ($_GET['loc'] > 0) && (isset($_GET['loc'])) && ($_GET['workexp'] <= 0) && ($_GET['type'] <= 0) && ($_GET['qualfctn'] <= 0)) {
//it will carry out the search, when just the loc select box has been selected
} else if (($_GET['ind'] <= 0) && ($_GET['spec'] <= 0) && ($_GET['loc'] <= 0) && ($_GET['workexp'] > 0) && isset($_GET['workexp']) && ($_GET['type'] <= 0) && ($_GET['qualfctn'] <= 0)) {
//it will carry out the search, when just the workexp select box has been selected
} else if (($_GET['ind'] <= 0) && ($_GET['spec'] <= 0) && ($_GET['loc'] <= 0) && ($_GET['workexp'] <= 0) && ($_GET['type'] > 0) && isset($_GET['type']) && ($_GET['qualfctn'] <= 0)) {
//it will carry out the search, when just the type select box has been selected
} else if (($_GET['ind'] <= 0) && ($_GET['spec'] <= 0) && ($_GET['loc'] <= 0) && ($_GET['workexp'] <= 0) && ($_GET['type'] <= 0) && ($_GET['qualfctn'] > 0) && isset($_GET['qualfctn'])) {
//it will carry out the search, when just the qualfctn select box has been selected
}
}
나는 이와 같은 검색에 대한 코드를 작성할 수 있지만, 25 개의 다른 else 문과이보기 복합체 여야합니다.
은이 같은 알고리즘에 배치 된 6 개 검색 파라미터 갖도록 순열 및 조합 수학 식을 사용했을 때, 사용자가 검색 필터를 선택하면,이 I 만든 검색 필터 알고리즘 인ind, spec, loc, workexp, type, qualfctn, ind & spec, ind & loc, ind & workexp, ind & type, ind & qualfctn, spec & loc, spec & workexp, spec & type, spec & qualfctn, loc & workexp, loc & type, loc & qualfctn, workexp & type, workexp & qualfctn, type & qualfctn, ind & spec & loc & workexp & type & qualfctn, ind & spec & loc & workexp & type, ind & spec & loc & workexp, ind & spec & loc.
을, 즉 다른 방식으로
PHP에서 검색 플러그인, 프레임 워크 또는 Librbary가 나를 위해이 작업을 수행 할 수 있으며 여러 필터로 검색하고 내가 작성한 코드의 양을 최소화 할 수 있으므로이 코드를 작성하거나 다시 작성하지 않아도됩니다. 바퀴는 다시 한번, 나는 무엇을해야하고 어떻게해야하는지에 대해 정말로 혼란 스럽습니다.
'에''그 기본 옵션'<옵션 값 = '0'> 업종 선택을 변경하고 PHP 코드'는 isset을 ($ _ GET [ '공업'])'사용하여 테스트 받기 . 이렇게하면 훨씬 더 깨끗해 보입니다. –
까마귀 까마귀 나는 이해하지 못합니다, 당신은 더 설명 할 수 있습니까? –
기본적으로 SQL 문자열 작성기 패턴을 찾고 있습니다. –