我有个问题。我正在使用此代码:
$sql = "SELECT Id, FileName FROM Templates ORDER BY DateTimeUploaded DESC";
if($result = $conn->query($sql))
{
if($result->num_rows >= 1)
{
while($row = $result->fetch_object())
{
$arrTotal["Templates"] = array($row);
}
$result->free();
}
$arrTotal["Source"] = "media/templates/";
echo json_encode($arrTotal);
}
但是当我打印 json 时,$arrTotal["Templates"]
它只有一行,但它有 17 行。我究竟做错了什么?
您反复为数组成员赋值,需要添加[]
以避免这种情况:
while($row = $result->fetch_object())
{
$arrTotal["Templates"][] = array($row);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句