我编写了上面的代码,它从用户那里获取了它的值。它的工作但日期过滤器不起作用。相反,即使提供日期,它也会显示表中的所有记录。
可能是什么问题?
$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."' )
";
答案 0 :(得分:0)
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."' )";
答案 1 :(得分:0)
假设您在 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."' )
";