0

所有 Mysql 查询似乎都适用于我表中“年龄”的完美预期条件。例如我需要年龄来过滤这个条件从age >=20to age <=30,everting 似乎工作但不是年龄。

例如检查这里的链接一个链接

$sql = "SELECT * FROM  `file_records` 
           WHERE  (`country` = '$country' OR '$country' IS NULL) 
               OR (`gender` = '$gender' OR'$gender' IS NULL) 
               OR (`cast` = '$cast' OR '$cast' IS NULL) 
               OR (
                   (`age` >= '$age_from' OR   '$age_from' IS NULL) 
                     AND (`age` <= '$age_to' OR '$age_to' IS NULL)
                  ) 
           LIMIT 0 , 30";
4

4 回答 4

0

您可以使用 mysql BETWEEN函数,例如

age BETWEEN 20 AND 30
于 2013-01-03T03:57:00.400 回答
0

您正在检查 >= 的 from 和 to date .. 试试这个 ..

$sql = "SELECT * FROM  `file_records` 
         WHERE (`country` = '$country' OR '$country' IS NULL) 
           OR (`gender` = '$gender' OR' $gender' IS NULL) 
           OR (`cast` = '$cast' OR '$cast' IS NULL) 
           OR ((`age` >= '$age_from' OR '$age_from' IS NULL) 
                AND (`age` <= '$age_to' OR '$age_to' IS NULL)) 
         LIMIT 0 , 30";
于 2013-01-03T03:58:24.083 回答
0

您可以像这种格式一样在和运算符之间选择年龄

SELECT column_name(s)
FROM table_name
WHERE age
BETWEEN age >=20 and age <=30
于 2013-01-03T03:59:39.790 回答
0

如果你echo $sql;,你会发现这是不可能的 '' IS NULL

你想要类似的东西

OR ((`age` >= '$age_from' OR '$age_from' = '') 
            AND (`age` <= '$age_to' OR '$age_to' = '')) 
于 2013-01-03T04:11:50.920 回答