我有一个搜索表单,用户可以在其中搜索指定价格范围内的产品。其中我有 2 个输入框 1 用于起始范围,另一个用于结束范围。
我的数据库表中有 3 个产品商店。与价格2300.0000
,1200.0000
,1000.5000
分别。
我在输入的价格范围内选择值时遇到问题。问题是,当我输入像
100
开始范围到1100
结束范围。带有1200.0000
和1000.5000
正在显示的产品,而不仅仅是1000.5000
产品。0
开始范围到1100
结束范围或1000.50
结束范围。带有1200.0000
和1000.5000
正在显示的产品,而不仅仅是1000.5000
产品。1100
起始范围。仅显示带有 的产品,2300.0000
而不是同时显示2300.0000
和1200.0000
。但是当起始值小于或等于时,500
所有 3 个产品都将被显示。
这是我正在使用的代码。
function db_prepare_input($string)
{
if (is_string($string)) {
return trim(stripslashes($string));
} elseif (is_array($string)) {
reset($string);
while (list($key, $value) = each($string)) {
$string[$key] = db_prepare_input($value);
}
return mysql_real_escape_string($string);
} else {
return mysql_real_escape_string($string);
}
}
$pricefrom_key = db_prepare_input(number_format($_GET['pricefrom'], 4, '.', ''));
$priceto_key = db_prepare_input(number_format($_GET['priceto'], 4, '.', ''));
// Price Range
if (!empty($_GET['pricefrom']) && !empty($_GET['priceto'])) {
$price_range = " having price >= ".$pricefrom_key." and price <= ".$priceto_key;
}
elseif(empty($_GET['pricefrom']) && !empty($_GET['priceto']))
{
$price_range = " having price >= 0 and price <= ".$priceto_key;
}
elseif(!empty($_GET['pricefrom']) && empty($_GET['priceto']))
{
$price_range = " having price >= ".$pricefrom_key;
}
elseif(!empty($_GET['pricefrom']) && !empty($_GET['priceto']))
{
$price_range = "";
}
$catglobal_sql = "select p.blog_id, p.global_category_id, p.products_id, p.products_currency, p.products_type, p.products_name, p.products_description, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_weight, p.products_status, p.products_tax_class_id, p.manufacturers_id, p.products_ordered, p.specials_new_products_price, p.specials_date_added, p.specials_last_modified, p.expires_date, p.date_status_change, p.status, p.display_product, case when (p.specials_new_products_price > 0 or p.specials_new_products_price != 0000-00-00 and p.expires_date > Now() and p.status != 0) then p.specials_new_products_price else p.products_price end price from ".TABLE_GLOBAL_PRODUCTS." p INNER JOIN ".TABLE_STORES." s ON s.blog_id = p.blog_id where MATCH (p.products_name,p.products_description) AGAINST ('%".$search_key."%') OR p.products_name like '%".$search_key."%' and s.countries_id = '168' ".$search_cat." and p.display_product = '1' and p.products_status = '1' ".$price_range." order by p.products_date_added DESC, p.products_name";
我试过,添加die($catglobal_sql);
,结果是,
select p.blog_id, p.global_category_id, p.products_id, p.products_currency, p.products_type, p.products_name, p.products_description, p.products_quantity, p.products_model, p.products_image, p.products_price, p.products_date_added, p.products_last_modified, p.products_date_available, p.products_weight, p.products_status, p.products_tax_class_id, p.manufacturers_id, p.products_ordered, p.specials_new_products_price, p.specials_date_added, p.specials_last_modified, p.expires_date, p.date_status_change, p.status, p.display_product, case when (p.specials_new_products_price > 0 or p.specials_new_products_price != 0000-00-00 and p.expires_date > Now() and p.status != 0) then p.specials_new_products_price else p.products_price end price from wp_global_products_table p INNER JOIN wp_blogs s ON s.blog_id = p.blog_id where MATCH (p.products_name,p.products_description) AGAINST ('%cotton%') OR p.products_name like '%cotton%' and s.countries_id = '168' and p.products_currency = 'php' and p.display_product = '1' and p.products_status = '1' and p.products_type = 'a' having price >= 0 and price <= 1200.0000 order by p.products_date_added DESC, p.products_name
好像有什么问题??