[英]Search query doesn't return desired results
I have kind of advanced search function.我有一种高级搜索功能。 All works fine except one AND LIKE ...
.除了一个AND LIKE ...
之外AND LIKE ...
一切正常。 There are two options A
or A, *AB
.有两个选项A
或A, *AB
。 I want when I choose A
to return results only which are A
in database and when I choose A, *AB
to return results which are only A, *AB
.我希望当我选择A
时只返回数据库中A
结果,当我选择A, *AB
时返回只有A, *AB
。
What is happening now is that when I choose B, *AB
it returns results which for both现在发生的事情是,当我选择B, *AB
它会返回两个结果
A
A, *AB
My form is with action get
.我的表格是带有 action get
。 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 html 选择选项菜单有
<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 take ge
在查询中,这是采取ge
的行
$couGe=($ge == "None") ? "" : "AND c.ge LIKE '".substr($ge, 0, 2)."%'";
When I var_dump($_GET['ge']
I see that I get what I choose. I'm very confused and any help is appreciated.当我var_dump($_GET['ge']
我看到我得到了我选择的东西。我很困惑,任何帮助表示赞赏。
You need to change a bit your query and the way you assign $couGe
where you took selected ge
.您需要稍微更改您的查询以及您将$couGe
分配到您选择的ge
。 Please try this way请尝试这种方式
$couGe=($ge == "None") ? "" : "'".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 $couTea AND c.ge LIKE $couGe
ORDER BY s.dept,s.dept_code");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.