我一直在絞盡腦汁想要獲得一些看似簡單的工作。我有一個表「重量」。重量有3列「shipping_to」,「shipping_from」和「shipping_cost」。PHP在MySQL中使用大於號和小於號在MySQL中選擇值
Shipping_to和Shipping_from是權重值和運輸成本保持運輸成本,如果該值大於或等於X且小於或等於X
我寫了這個一百萬個不同的方式和我的生活是行不通的。
更新: 腳本工作「種」,但它永遠不會返回1的成功響應,它永遠不會吝嗇X的價值,即使我已經手動將這些值放入我的MySQL分貝。
php腳本:
if($The_Function=="SHIPPING_COST"){
$response = array();
require_once __DIR__ . '/db_connect.php';
$con = new DB_CONNECT();
$ship_weight = 1;
$result = mysql_query("SELECT * FROM weight WHERE from_weight >= '$ship_weight' AND to_weight <= '$ship_weight'");
if(!empty($result)){
if (mysql_num_rows($result) > 0) {
$response["userID"] = array();
while ($row = mysql_fetch_array($result)) {
$custID = array();
$custID["shipping_cost"] = $row["shipping_cost"];
array_push($response["userID"], $custID);
}
$response["success"] = 1;
echo json_encode($response);
}else {
$response["success"] = 0;
$response["message"] = "No shipping found";
echo json_encode($response);
}
}else {
$response["success"] = 0;
$response["message"] = "No shipping found";
echo json_encode($response);
}
}
能否請您詳細說明什麼是不工作的,即:您獲得了什麼價值 - 這種方式有助於我們應該看哪些部分。 – azngunit81
在上面添加了更多信息。 –
from_weight> ='$ ship_weight'AND to_weight <='$ ship_weight' - 哪個重量越來越小? – azngunit81