Skip to main content
added 183 characters in body
Source Link
Ty Jacobs
  • 113
  • 2
  • 8
  • 23

I have been racking my brains trying to get something that seems simple to work. I have a TABLE "weight". Weight has 3 columns "shipping_to", "shipping_from", and "shipping_cost".

Shipping_to and Shipping_from are the weight values and shipping cost holds the shipping cost if the value is greater than or equal to X AND less than or equal to X.

I have written this a million different ways and for the life of me it won't work.

UPDATED: The Script works "kind of" but it never returns a success response of 1 and it never fimds the value of X even though I have manually put these values into my MySQL db.

PHP SCRIPT:

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);
    }
}

I have been racking my brains trying to get something that seems simple to work. I have a TABLE "weight". Weight has 3 columns "shipping_to", "shipping_from", and "shipping_cost".

Shipping_to and Shipping_from are the weight values and shipping cost holds the shipping cost if the value is greater than or equal to X AND less than or equal to X.

I have written this a million different ways and for the life of me it won't work.

PHP SCRIPT:

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);
    }
}

I have been racking my brains trying to get something that seems simple to work. I have a TABLE "weight". Weight has 3 columns "shipping_to", "shipping_from", and "shipping_cost".

Shipping_to and Shipping_from are the weight values and shipping cost holds the shipping cost if the value is greater than or equal to X AND less than or equal to X.

I have written this a million different ways and for the life of me it won't work.

UPDATED: The Script works "kind of" but it never returns a success response of 1 and it never fimds the value of X even though I have manually put these values into my MySQL db.

PHP SCRIPT:

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);
    }
}
Removing completely irrelevant Android tag.
Link
Bryan Herbst
  • 67.4k
  • 10
  • 137
  • 120
Source Link
Ty Jacobs
  • 113
  • 2
  • 8
  • 23

PHP Select Value in MySQL Using Greater Than and Less Than

I have been racking my brains trying to get something that seems simple to work. I have a TABLE "weight". Weight has 3 columns "shipping_to", "shipping_from", and "shipping_cost".

Shipping_to and Shipping_from are the weight values and shipping cost holds the shipping cost if the value is greater than or equal to X AND less than or equal to X.

I have written this a million different ways and for the life of me it won't work.

PHP SCRIPT:

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);
    }
}