我有一个MySQL全文搜索引擎,我希望允许用户通过为结果添加一系列年份来过滤结果。我有一个名为year
的专栏,其年份介于1999年至2011年之间。如何更改我的mysql_query
以反映这一点?变量$fyear
是用户想要开始的年份(低端),$tyear
是结束年份(高端)。
<?php
mysql_connect("localhost", "root", "root");
mysql_select_db("database");
$var = @$_GET['q'];
$fyear = @$_GET['from_year'];
$tyear = @$_GET['to_year'];
if (isset($var)) {
$sql = mysql_query("SELECT *, MATCH(subj_name, course_name) AGAINST ('$var')
AS score from table1 WHERE MATCH (subj_name, course_name) AGAINST('$var')
ORDER BY score desc");
}
注意:列year
是一个整数字段
答案 0 :(得分:1)
查看运营商between。
$sql = mysql_query("SELECT *, MATCH(subj_name, course_name) AGAINST ('$var') AS
score from table1 WHERE year BETWEEN '$fyear' AND '$tyear' MATCH (subj_name, course_name) AGAINST('$var') ORDER
BY score desc");
答案 1 :(得分:0)
我不熟悉全文搜索,但您不能像这样添加查询条件吗?
$sql = mysql_query("SELECT *, MATCH(subj_name, course_name) AGAINST ('$var') AS
score from table1 WHERE year BETWEEN $fyear AND $tyear AND MATCH (subj_name, course_name) AGAINST('$var') ORDER BY score desc");