应用程序将带有POST方法的String / Jsonobject发送到PHP文件。 我想使用该值在查询中设置限制
$sql = "select * from posts ORDER BY post_id DESC LIMIT $tag";
我可以收到它,但我不能将它用于我的查询。 我得到的错误像“java.lang.string无法转换为jsonarray” 我试图将其转换为整数:
$int = intval($tag);
但查询仍然没有将其视为整数..
还有另一种方法可以将一个Int从Activity.java转移到php,以便我可以在ORDER BY post_id DESC LIMIT之后将它放入查询中吗?
爪哇
RequestQueue queue = Volley.newRequestQueue(this);
Map<String, String> params = new HashMap<>();
params.put("tag", "2");
JSONObject o = new JSONObject(params);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
Request.Method.POST,
腓
<?php
//open connection to mysql db
$connection = mysqli_connect("xxxxx","xxxx","xxxx","xxxx")
or die("Error " . mysqli_error($connection));
$data = json_decode(file_get_contents('php://input'), true);
if (empty($data['tag']) == false) {
$tag = $data['tag'];
}
//fetch table rows from mysql db
$sql = "select * from posts ORDER BY post_id DESC LIMIT $tag";
$result = mysqli_query($connection, $sql)
or die("Error in Selecting " . mysqli_error($connection));
答案 0 :(得分:0)
你能试试吗
$sql = "select * from posts ORDER BY post_id DESC LIMIT '".$tag."';";