这是我的 PHP 代码
// category filter
if(!isset($_POST['products']) || $_POST['products'] == ""){
$category_filter = "";
} else {
$category_filter = " AND cat_id='".$_POST['products']."'";
}
// offers filter
if($_POST['offer'] != "YES")
{
$offer_filter = "";
} else {
$offer_filter = " AND offer=1";
}
$sql = $db->get_rows("
SELECT *, ( 3959 * ACOS( COS( RADIANS(".$_POST['lat'].") ) * COS( RADIANS( latitude ) ) * COS( RADIANS( longitude ) - RADIANS(".$_POST['lng'].") ) + SIN( RADIANS(".$_POST['lat'].") ) * SIN( RADIANS( latitude ) ) ) ) AS distance
FROM stores
WHERE status=1 AND approved=1 ".$offer_filter." ".$category_filter."
HAVING distance <= ".$_POST['distance']."
ORDER BY distance ASC
LIMIT 0,60");
我希望$offer_filter
在上面的 SQL 查询中获得正确的值,因为$category_filter
. 我想我在某个地方遗漏了一些东西......请如果有人可以帮助我......
以下是我在复选框输入的 php 索引文件中的 HTML 代码...
<input type="checkbox" name="offer" value="Yes" onChange="cachesearch = '';$('#clinic-finder-form').submit();"> Discount Offers Available