0
我的查詢是做比較數據庫的數據,如果數據庫內容等於或大於搜索條件($肌肉),然後選擇數據結果。邏輯需求,查詢結構混淆
* -1是一種價值意味着「無限」
的問題是,當數據庫中的數據爲-1,「事實上,它比每一個正整數小」,但在我的數據庫,它比所有的數字更大。執行select查詢將數據庫的內容導入結果,當數據庫內容等於-1時如何才能控制情況?
這裏是我的代碼:
$device = $_POST['device'];
$provider1 = $_POST['provider1'];
$plantype = $_POST['plantype'];
$dusage = $_POST['dusage'];
$cusage = $_POST['cusage'];
$musage = $_POST['musage'];
//default query
$MSGQuery = " plan.`MSG` >= $musage ";
//when search criteria is unlimited
if($musage == 'Unlimited'){
$MSGQuery = " plan.`MSG` = -1 ";
}//when search criteria is 0
else if ($musage == 0){
$MSGQuery = " plan.`MSG` >= -1 ";
}
else {
$MSGQuery = " plan.`MSG` >= $musage ";
}
echo $planquery="
SELECT plan.*, details.* FROM plan
LEFT JOIN details ON plan.`Name` = details.`Name`
WHERE plan.`Phone` = '$device'
AND plan.`SIMTYPE` = '$plantype'
AND plan.`DATA` >= $dusage
AND plan.`CALL` >= $cusage
AND $MSGQuery ";
$planresult=mysql_query($planquery)
or die ("Query to get data from firsttable failed: ".mysql_error());
while ($prow = mysql_fetch_assoc($planresult)) {