【发布时间】:2026-01-22 18:35:01
【问题描述】:
我在尝试从服务器获取数据时遇到了问题。我用凌空将arraylist数据发送到php服务器。
ArrayList<String> list = new ArrayList<>();
list.add("data1");
list.add("data2");
list.add("data3");
String finalRequestedList = new Gson().toJson(list);
我将上面的 json 正确发送到服务器并在 php 上接收到它。但我无法在我的 android 上运行查询并从服务器获取响应。
下面是我的php代码:
$data =$_POST['data'];
$content = json_decode($data,true);
$in = str_repeat('?,', count($content) - 1) . '?';
$query = "SELECT * from table where column = '$in'";
$result=$connection->prepare($query);
$result->execute($content);
$rows = $result->fetchAll(PDO::FETCH_ASSOC);
print json_encode($rows);
我的目标是运行这些查询并从数据库中获取响应并将其返回到 android。
$query = "SELECT * from table where column = 'data1,data2,data3'";
有人可以帮我处理这个案子吗?在此先感谢。
编辑: 凌空将此json发送到服务器:
["data1","data2","data3"]
我在 php 上遇到了这个错误(行不同,因为我有一些与这部分无关的其他代码):
Warning: count(): Parameter must be an array or an object that implements
Countable in domain.com/get_data.php on line 76 Warning: str_repeat(): Second
argument has to be greater than or equal to 0 in domain.com/get_data.php on
line 76 []
【问题讨论】:
-
错误是什么?
-
为什么不使用 'data1' 或 'data2' 或 'data3' 并且您可以对所有 3 种选择使用 UNION 以便您只有一个查询
-
我编辑了它。我想说我需要这些查询的结果。
-
这将有助于分享两件事:1)您从 android/java 代码发送的 JSON 字符串的确切内容和 2)您在 PHP 端遇到的确切错误。跨度>
-
我添加了json和php错误。
标签: php android mysql pdo android-volley