除了价格范围输入外,我设法让所有过滤器都正常工作。我尝试使用
AND `price` BETWEEN '".$lowest_price."' AND '".$highest_price."'
但这没有帮助。以下是条件:
$lowest_price = '0'; $highest_price = '999999999';
if(empty($_POST['lowest_price']) === false){
$lowest_price = $_POST['lowest_price'];
}
if(empty($_POST['highest_price']) === false){
$highest_price = $_POST['highest_price'];
}
$price_range = "AND `price` >= '".$lowest_price."' AND `price` <= '".$highest_price."'";
mysql_query("SELECT * FROM `classifieds` WHERE ".$category." ".$price_range." ".$order_list." LIMIT 10");
为什么这些项目对输入的最低和最高价格没有反应? 非常感谢任何帮助!
答案 0 :(得分:0)
你的价格范围是字符串使它首先像这样整数
$lowest_price = 0; $highest_price = 999999999;
如果varchar / text必须将列的类型更改为int / float / double(数字格式)以进行比较,还可以考虑数据库表price
中classifieds
字段的类型是什么
注意: mysql_*
现已弃用,请使用mysqli_*
或pdo
更新2:
$lowest_price = '0'; $highest_price = '999999999';
if(isset($_POST['lowest_price']) && trim($_POST['lowest_price'])!=""){
$lowest_price = trim($_POST['lowest_price']);
}
if(isset($_POST['highest_price']) && trim($_POST['highest_price'])!=""){
$highest_price = trim($_POST['highest_price']);
}
$price_range = " AND `price`>=$lowest_price AND `price`<=$highest_price";
echo "SELECT * FROM `classifieds` WHERE ".$category." ".$price_range." ".$order_list." LIMIT 10";
// this will print your query try to run this query in phpmyadmin and see the results
mysql_query("SELECT * FROM `classifieds` WHERE ".$category." ".$price_range." ".$order_list." LIMIT 10");