可以說我在表中有以下信息。 -1意味着無限MySQL查詢不返回預期結果
Price Minutes SMS Data
7.50 200 -1 250
10 250 -1 1000
12 250 -1 -1
在我的形式,我有許多領域,如果你想無限的東西複選框,所以我有一個SQL查詢具有幾個變量取決於如果複選框被選中一樣所以:
//check to see if minutes is set as unlimited. if they are, set sms as -1
if ($minunlim=="on"){
$minquery = "minutes = -1";
$minutes = "Unlimited";
} else {
$minutes = $_GET["minutes"];
$minquery = "minutes >= '$minutes' OR minutes = -1";
}
//check to see if sms is set as unlimited. if they are, set sms as -1
if ($smsunlim=="on"){
$smsquery = "sms = -1";
$sms = "Unlimited";
} else {
$sms = $_GET["sms"];
$smsquery = "sms >= '$sms' OR sms = -1";
}
//check to see if sms is set as unlimited. if they are, set sms as -1
if ($dataunlim=="on"){
$dataquery = "data = -1";
$data = "Unlimited";
} else {
$data = $_GET["data"];
$dataquery = "data >= '$data' OR data = -1";
}
//run query
$getprices = $this->db->query("SELECT * FROM gg_Crates WHERE
price <= '$price' AND $minquery
AND ($smsquery)
AND ($dataquery)");
所以我的標準我用的是價格= 36分鐘= 100,SMS = 200,數據= 300和我的期望是在這種情況下,唯一的物品返回將是行的,其價格是10和12(因爲第一行的數據低於300)
查詢其輸出是:
SELECT * FROM gg_Crates WHERE price <= '36' AND minutes >= '100' OR minutes = -1 AND (sms >= '200' OR sms = -1) AND (data >= '300' OR data = -1)
在我的腦海裏讀取
是那些價格比36分鐘是大於或等於 100或等於-1選擇一切。並且SMS大於或等於200或 等於-1。而數據是大於或等於300或等於-1
有在聲明中沒有哪里哪里是應該拉7.50行作爲數據低於250
但是實際效果我得到的是它將返回所有3行。有什麼建議麼?
表現出更多的代碼......你在哪裏設置$價格,$ smsunlim等 –