php - Search query doesn't return desired results
I have kind of advanced search function. All works fine except oneAND LIKE ...
.
There are two optionsA
orA, *AB
. I want when I chooseA
to return results only which areA
in database and when I chooseA, *AB
to return results which are onlyA, *AB
.
What is happening now is that when I chooseB, *AB
it returns results which for both
A
A, *AB
My form is with actionget
. This is my query
$couGe=($ge == "None") ? "" : "AND c.ge LIKE '".substr($ge, 0, 2)."%'";
$active = ($this->showCouCancelled) ? "AND (c.active=1 OR c.active=7)" : "";
$active = ($this->hideCouActive) ? "AND (c.active=1 OR c.active=3 OR c.active=4 OR c.active=7)" : "";
$couName = ($cName) ? "AND course_title LIKE '%$cName%'" : "";
$couDept = ($cDept) ? "AND s.dept='$cDeptArray[0]' AND s.dept_code='$cDeptArray[1]'" : "";
$iRes = _SQLQuery("
SELECT DISTINCT c.id,s.dept,s.dept_code,c.course_title,c.active,s.year,s.sem,c.ge,c.course_type
FROM courses AS c, sections AS s, teachers as t, tea_sec_rel as tsr
WHERE s.course_id_rel=c.id AND $curYr $curSem $active $couName $couDept $psSearch $couGe
ORDER BY s.dept,s.dept_code");
The html select option menu has
<select name="ge" id="ge">
<option value="None">All</option>
<option value="A">A</option>
<option value="A, *AB">A, *AB</option>
</select>
On the query this is the line which takege
$couGe=($ge == "None") ? "" : "AND c.ge LIKE '".substr($ge, 0, 2)."%'";
When Ivar_dump($_GET['ge']
I see that I get what I choose. I'm very confused and any help is appreciated.
Answer
Solution:
You need to change a bit your query and the way you assign
$couGe
where you took selectedge
. Please try this way