[英]Search query doesn't return desired results
我有一种高级搜索功能。 除了一个AND LIKE ...
之外AND LIKE ...
一切正常。 有两个选项A
或A, *AB
。 我希望当我选择A
时只返回数据库中A
结果,当我选择A, *AB
时返回只有A, *AB
。
现在发生的事情是,当我选择B, *AB
它会返回两个结果
A
A, *AB
我的表格是带有 action get
。 这是我的查询
$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");
html 选择选项菜单有
<select name="ge" id="ge">
<option value="None">All</option>
<option value="A">A</option>
<option value="A, *AB">A, *AB</option>
</select>
在查询中,这是采取ge
的行
$couGe=($ge == "None") ? "" : "AND c.ge LIKE '".substr($ge, 0, 2)."%'";
当我var_dump($_GET['ge']
我看到我得到了我选择的东西。我很困惑,任何帮助表示赞赏。
您需要稍微更改您的查询以及您将$couGe
分配到您选择的ge
。 请尝试这种方式
$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.