PHP价格范围过滤器从最低到最高从输入更新
我设法让我所有的过滤器工作,除了价格范围输入。我试着用PHP价格范围过滤器从最低到最高从输入更新,php,Php,我设法让我所有的过滤器工作,除了价格范围输入。我试着用 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'];
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'$最高价格='9999999';
如果(空($_POST['lovel_price'])==false){
$looster_price=$_POST['looster_price'];
}
如果(空($_POST['highest_price'])==false){
$highest_price=$_POST['highest_price'];
}
$price\u range=“AND`price`>=”“$lower\u price.”和`price`您的价格范围是字符串,请先将其设置为整数,如下所示
$lowest_price = 0; $highest_price = 999999999;
再想一想,数据库表classifieds
中price
字段的类型是什么,如果是varchar/text,则必须将列的类型更改为int/float/double(数字格式)进行比较
注意: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");
最低价格='0';最高价格='9999999';
如果(isset($\u POST[‘最低价格’])和trim($\u POST[‘最低价格’])!=“”){
$looster_price=trim($u POST['looster_price']);
}
如果(isset($\u POST['highest\u price'])和trim($\u POST['highest\u price'])!=“”){
$highest_price=trim($u POST['highest_price']);
}
$price\u range=“AND`price`>=$lovel\u price AND`price`您在classifieds
表中的price
字段的类型是什么数据库中的price字段是int(25),我修复了您上面所说的,但仍然没有运气这真的很奇怪,只有在我首先选择一个类别或不同的项目顺序时,它才能正常工作,但如果我从价格范围输入开始,它不会对页面产生任何影响。。。这可能是什么?我已经回显了select查询将打印什么请显示select*FROMclassifieds
WHEREcategory\u id
='1'和price
=10和price
hmmm我想我知道问题出在哪里了。在phpmyadmin中运行它之后,我注意到我有一些列被设置为0(我猜这是在我测试东西时发生的),所以它忽略了这一点。而且,我的一些情况似乎不起作用。。该调试了!