繁体   English   中英

mysql的where子句中的条件日期未过滤

[英]Conditional date in where clause of mysql not filtering

我已经编写了上面的代码,它从用户那里获取它的值。 它的工作,但日期过滤器不工作。 相反,即使提供了日期,它也会显示表中的所有记录。

可能是什么问题?

$exp_query = "SELECT DISTINCT property_name, property_id, Water_charges, bank_charges, charge_1_description, other_charges_1,
                charge_2_description, other_charges_2, dates ";
$exp_query .="FROM expenses ";
$exp_query .="WHERE
              1=1
              AND (property_name= '".$property."'
                    OR dates BETWEEN '".$datefro."' AND '".$dateto."' )
                ";

AND 和 OR 之间有区别,还有如何在 AND 条件下使用 OR。 您在括号中使用了 OR 条件,请检查它们。

$exp_query = "SELECT DISTINCT property_name, property_id, Water_charges, bank_charges, charge_1_description, other_charges_1,
                charge_2_description, other_charges_2, dates ";
$exp_query .="FROM expenses ";
$exp_query .="WHERE property_name= '".$property."'
              AND (dates BETWEEN '".$datefro."' AND '".$dateto."' )";

假设您在MYSQL查询中使用了正确的条件

只需使用MYSQL DATE()函数,例如:

$exp_query = "SELECT DISTINCT property_name, property_id, Water_charges, bank_charges, charge_1_description, other_charges_1,
                charge_2_description, other_charges_2, dates ";
$exp_query .="FROM expenses ";
$exp_query .="WHERE
              1=1
              AND (property_name= '".$property."'
                    OR DATE( dates ) BETWEEN '".$datefro."' AND '".$dateto."' )
                ";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM