Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL where子句,带有显示特定年龄的条件_Php_Mysql_Conditional Statements - Fatal编程技术网

Php MySQL where子句,带有显示特定年龄的条件

Php MySQL where子句,带有显示特定年龄的条件,php,mysql,conditional-statements,Php,Mysql,Conditional Statements,所有Mysql查询似乎都能在我的表中的“age”条件下正常工作。例如,我需要age来过滤这个条件,从age>=20到age,您可以像这样使用mysql函数 age BETWEEN 20 AND 30 您正在检查>=的起始日期和截止日期。。试试这个 $sql = "SELECT * FROM `file_records` WHERE (`country` = '$country' OR '$country' IS NULL) OR (`gender`

所有Mysql查询似乎都能在我的表中的“age”条件下正常工作。例如,我需要age来过滤这个条件,从
age>=20
age,您可以像这样使用mysql函数

age BETWEEN 20 AND 30

您正在检查>=的起始日期和截止日期。。试试这个

$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";
$sql=“从“文件记录”中选择*
其中(`country`='$country'或'$country'为空)
或(`gender`='$gender'或'$gender'为空)
或(`cast`='$cast'或'$cast'为空)
或(`age`>='$age\u from'或'$age\u from'为空)

和(`age`您可以在和运算符之间选择年龄,如此格式

SELECT column_name(s)
FROM table_name
WHERE age
BETWEEN age >=20 and age <=30
选择列名称
从表\u名称
什么年龄

在年龄>=20和年龄之间,如果您
echo$sql;
,您会发现这是不可能的
''为空
为真

你想要什么

OR ((`age` >= '$age_from' OR '$age_from' = '') 
            AND (`age` <= '$age_to' OR '$age_to' = '')) 
或(`age`>='$age\u from'或'$age\u from'='')
和(`年龄`
OR ((`age` >= '$age_from' OR '$age_from' = '') 
            AND (`age` <= '$age_to' OR '$age_to' = ''))