我正在编写代码,并且需要从数据库中读取每个零件的数量,问题是所有零件的列数量都是相同的,当我将它们分配给我的Android Studio代码时,为所有请求的字段输出相同的值。我需要如何告诉应用程序获取其他数量的帮助 查询:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul id="list1"></ul>
输出:
<?php
include "connection.php";
$consulta = "SELECT * from parts ; ";
$result = $con -> query($consulta);
while($fila = $result -> fetch_array()){
$usuarios[] = array_map('utf8_encode', $fila);
}
echo json_encode($usuarios);
$result -> close();
我想在android studio上显示数量的输出
这是用于从数据库读取的android studio代码:
[
{"0":"1","idparts":"1","1":"resistor","partsName":"resistor","2":"13","Quantity":"13"},
{"0":"2","idparts":"2","1":"capacitor","partsName":"capacitor","2":"10","Quantity":"10"},
{"0":"3","idparts":"3","1":"inductor","partsName":"inductor","2":"10","Quantity":"10"},
{"0":"4","idparts":"4","1":"multimeter","partsName":"multimeter","2":"10","Quantity":"10"},
{"0":"5","idparts":"5","1":"arduino","partsName":"arduino","2":"10","Quantity":"10"},
{"0":"6","idparts":"6","1":"rasberry","partsName":"rasberry","2":"10","Quantity":"10"},
{"0":"8","idparts":"8","1":"wires","partsName":"wires","2":"10","Quantity":"10"},
{"0":"9","idparts":"9","1":"breadboard","partsName":"breadboard","2":"10","Quantity":"10"}
]
答案 0 :(得分:0)
fetch_array
默认情况下将同时返回一个数字数组和一个assoc数组,您只是感到困惑。
代替我们fetch_assoc
,您将只获得assoc数组,这将更有意义
while($fila = $result->fetch_assoc()){
$usuarios[] = array_map('utf8_encode', $fila);
}
同样从您显示的json输出中,除第一行以外,所有其他行中
Quantity
均为13,而Quantity
则为10。