繁体   English   中英

我的数据库中有一个整数。 我正在努力获得正确的专栏

[英]I have an integer in my database. I'm tryingto get the right column

我的数据库中有一个整数,我正在尝试使用正确的列来显示数据库的其余部分

这就是我在Android工作室中提出的要求

public class SeeorderRequest extends StringRequest {
    private static String SEEORDER_REQUEST_URL="http:Seeorder.php";
    private Map<String, String> params;

    public SeeorderRequest(String ordernum, Response.Listener<String> listener){
        super(Method.POST, SEEORDER_REQUEST_URL, listener,null);
        params= new HashMap<>();
        params.put("ordernum",ordernum);

    }

    @Override
    public Map<String, String> getParams() {
        return params;
    }

这是我的PHP代码

<?php


// array for JSON response
$response = array();
define('DB_USER', ""); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', ""); // database name
define('DB_SERVER', ""); // db server
// array for JSON response



 $conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD,DB_DATABASE);

// check for post data
if (isset($_GET["ordernum"])) {
    $id = $_GET['ordernum'];

$sql = "SELECT * FROM orden WHERE orderid = $id";
$result = $conn->query($sql) or die (mysqli_connect_error());



    if (!empty($result)) {
        // check for empty result
        if (mysqli_num_rows($result) > 0) {

            $result = mysqli_fetch_array($result);

            $orden = array();
            $orden["ordernum"] = $result["orderid"];
            $orden["pilotname"] = $result["pilotname"];
            $orden["pilotcash"] = $result["pilotcash"];
            $orden["date"] = $result["date"];
            $orden["hoobsstart"] = $result["hoobsstart"];
            $orden["hoobsend"] = $result["hoobsend"];
            $orden["watchtime"] = $result["watchtime"];         
            $orden["hoobstime"] = $result["hoobstime"];
            $orden["gas"] = $result["gas"];
            $orden["liter"] = $result["liters"];            
            $orden["repairname"] = $result["repairname"];
            $orden["repaircost"] = $result["repaircost"];
            $orden["travelexpense"] = $result["patient_email"];
            $orden["othername1"] = $result["othername1"];
            $orden["othercost1"] = $result["othercost1"];

            // success
            $response["success"] = 1;

            // user node
            $response["myorder"] = array();

            array_push($response["myorder"], $orden);

            // echoing JSON response
            echo json_encode($response);
        } else {
            // no product found
            $response["success"] = 0;
            $response["message"] = "No product found";

            // echo no users JSON
            echo json_encode($response);
        }
    } else {
        // no product found
        $response["success"] = 0;
        $response["message"] = "No product found";

        // echo no users JSON
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}
?>

问题是在我的db中,order id的值是一个自动增量int,因此我无法使用此代码访问它,而android中的hashmap只接受字符串。

好的,我修复了问题是这一行:

$sql = "SELECT * FROM orden WHERE orderid = "$id";

它应该是

$sql = "SELECT * FROM orden WHERE orderid = $id";

这条线

if (isset($_GET["ordernum"])) {
    $id = $_GET['ordernum'];

它应该是

if (isset($_POST["ordernum"])) {
    $id = $_POST['ordernum'];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM